Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# AGENTS.md — uapi-sdk-python

This file tells AI coding agents how to use the **official Python SDK** for
the [uapis.cn](https://uapis.cn) public API platform.

## What this package is

Strongly-typed Python client for UAPI. Generated from the live OpenAPI 3.1
spec at <https://uapis.cn/openapi.json> — method names, parameter shapes,
and return types stay in lock-step with the real API.

```bash
pip install uapi-sdk-python
# or, with uv
uv add uapi-sdk-python
# or, with poetry
poetry add uapi-sdk-python
```

## Quick start

```python
from uapi import UapiClient

# Free-tier endpoints don't need an API key
client = UapiClient(base_url="https://uapis.cn")
weather = client.misc.get_misc_weather(city="北京")
print(weather)

# Paid endpoints take a key
import os
paid = UapiClient(base_url="https://uapis.cn", api_key=os.environ["UAPI_KEY"])
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Use the supported token parameter in auth docs

For paid-endpoint examples, this constructor call will fail because UapiClient.__init__ accepts token, not api_key, and the implementation sends it as Authorization: Bearer ... rather than X-API-Key (uapi/client.py lines 98-99 and 120-125). Agents following this new quick start will get TypeError: unexpected keyword argument 'api_key' before making any request.

Useful? React with 👍 / 👎.

ocr = paid.image.post_image_ocr(url="https://…/photo.png")
```

The client is grouped by tag (`misc`, `network`, `text`, `image`, `social`,
`translate`, `search`, …) and each method name matches the underlying
`operationId` from the OpenAPI spec, snake-cased.

## Discovery

When generating code, agents should:

1. Pull the spec from <https://uapis.cn/openapi.json> if you need a schema
that isn't in the local types yet.
2. Map the operation's `operationId` to a SDK method (`get-misc-weather` →
`client.misc.get_misc_weather`).
3. Pass the request parameters as keyword arguments.

## Authentication

- Many UAPI endpoints (network, text, random, convert, weather, time,
hotboard) work with no key.
- Paid endpoints want `X-API-Key`. The SDK forwards the `api_key`
constructor argument to that header.
- For human-in-the-loop OAuth flows, see
<https://uapis.cn/.well-known/oauth-authorization-server>.

## Errors

Every method raises a typed `UapiError` (subclass of `httpx.HTTPStatusError`)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Describe UapiError as the actual exception type

This states that UapiError subclasses httpx.HTTPStatusError, but the implementation defines class UapiError(Exception) in uapi/errors.py. Code generated from this guidance may catch httpx.HTTPStatusError and miss SDK errors entirely on non-2xx responses.

Useful? React with 👍 / 👎.

on non-2xx responses. The error body is a JSON object:
`{code, success: false, error, request_id?}`. Surface the `error` text
verbatim.

## Rate limits

Headers `X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset`,
`Retry-After` are returned on every response. Honor them — back off on
`429` and obey `Retry-After`.

## Async

The SDK is built on `httpx`, so an async client is also available:

```python
import asyncio
from uapi import AsyncUapiClient
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove the nonexistent async client example

This async example imports AsyncUapiClient, but the package exports only UapiClient from uapi/__init__.py, and a repo-wide search finds no AsyncUapiClient class. In any environment where an agent copies this section, from uapi import AsyncUapiClient fails immediately with an import error.

Useful? React with 👍 / 👎.


async def main():
async with AsyncUapiClient(base_url="https://uapis.cn") as client:
return await client.misc.get_misc_weather(city="上海")

print(asyncio.run(main()))
```

## Related repos

- MCP server: <https://github.com/AxT-Team/uapi-mcp> — same endpoints as MCP tools.
- Skills bundle: <https://github.com/AxT-Team/uapi-agent-skills>.
- Other languages: `uapi-sdk-typescript`, `uapi-sdk-go`, `uapi-sdk-rust`,
`uapi-sdk-java`, `uapi-sdk-csharp`, `uapi-sdk-cpp`, `uapi-sdk-php`.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 AxT-Team / UAPI

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
25 changes: 24 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,35 @@ build-backend = "setuptools.build_meta"
[project]
name = "uapi-sdk-python"
version = "0.1.17"
description = "Idiomatic UAPI SDK for Python"
description = "Official Python SDK for UAPI / uapis.cn — strongly-typed wrapper around 100+ free public-API endpoints (network, text, image, social, translation, search). Generated from the live OpenAPI 3.1 spec."
readme = "README.md"
license = {text = "MIT"}
requires-python = ">=3.9"
authors = [{name = "UAPI", email = "dev@uapis.cn"}]
keywords = ["uapi", "uapis", "uapis.cn", "sdk", "python", "rest", "rest-api", "openapi", "httpx", "public-api", "free-api", "agent", "ai", "mcp"]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries :: Python Modules",
"Typing :: Typed",
]
dependencies = ["httpx>=0.24.1"]

[project.urls]
Homepage = "https://uapis.cn/docs/sdk/python"
Documentation = "https://uapis.cn/docs"
Repository = "https://github.com/AxT-Team/uapi-sdk-python"
Issues = "https://github.com/AxT-Team/uapi-sdk-python/issues"
"OpenAPI Spec" = "https://uapis.cn/openapi.json"

[project.optional-dependencies]
dev = ["pytest", "mypy", "black", "isort"]

Expand Down
Loading