diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 0000000..f510d5a --- /dev/null +++ b/AGENTS.md @@ -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 — 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"]) +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 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 + . + +## Errors + +Every method raises a typed `UapiError` (subclass of `httpx.HTTPStatusError`) +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 + +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: — same endpoints as MCP tools. +- Skills bundle: . +- Other languages: `uapi-sdk-typescript`, `uapi-sdk-go`, `uapi-sdk-rust`, + `uapi-sdk-java`, `uapi-sdk-csharp`, `uapi-sdk-cpp`, `uapi-sdk-php`. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4e7b5fa --- /dev/null +++ b/LICENSE @@ -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. diff --git a/pyproject.toml b/pyproject.toml index 5b63aaf..d607136 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"]