Skip to main content

Idiomatic UAPI SDK for Python

Project description

uapi-sdk-python

Banner

Python Docs PyPI

[!NOTE] 所有接口的 Python 示例都可以在 UApi 的接口文档页面,向下滚动至 快速启动 区块后直接复制。

快速开始

pip install uapi-sdk-python
from uapi import UapiClient

client = UapiClient("https://uapis.cn", "YOUR_API_KEY")
result = client.social.get_social_qq_userinfo(qq="10001")
print(result)

[!TIP] 请使用与运行脚本相同的 Python 解释器安装依赖,例如执行 python -m pip install uapi-sdk-python 后再运行 python main.py。在 VS Code / Pyright 中若提示 “Import uapi could not be resolved”,将解释器切换到当前虚拟环境即可恢复补全。

特性

现在你不再需要反反复复的查阅文档了。

只需在 IDE 中键入 client.,所有核心模块——如 socialgameimage——即刻同步展现。进一步输入即可直接定位到 get_social_qq_userinfo 这样的具体方法,其名称与文档的 operationId 严格保持一致,确保了开发过程的直观与高效。

所有方法签名只接受真实且必需的参数。当你在构建请求时,IDE 会即时提示 qqusername 等键名,这彻底杜绝了在 dict/关键字参数中因拼写错误而导致的运行时错误。

针对 401、404、429 等标准 HTTP 响应,SDK 已将其统一映射为具名的异常类型。这些异常均附带 codestatusdetails 等关键上下文信息,确保你在日志中能第一时间准确、快速地诊断问题。

UapiClient(base_url, token, timeout) 默认使用 httpx 并自动追加 Authorization 头;需要切换环境或调整超时时,只要改一次构造参数即可。

如果你需要查看字段细节或内部逻辑,仓库中的 ./internal 目录同步保留了由 openapi-generator 生成的完整结构体,随时可供参考。

进阶实践

缓存与幂等

from functools import lru_cache
from uapi import UapiClient

client = UapiClient("https://uapis.cn", token="YOUR_API_KEY")

@lru_cache(maxsize=128)
def cached_lookup(qq: str):
    return client.social.get_social_qq_userinfo(qq=qq)

user = cached_lookup("10001")

也可以在 FastAPI / Django 项目里配合 Redis,将 SDK 的响应序列化后写入缓存,命中即直接返回。

调整超时与环境

from uapi import UapiClient

client = UapiClient(
    "https://uapis.cn",
    token="YOUR_API_KEY",
    timeout=5.0,
)

如果你需要切换到别的环境,直接改 base_url 就可以;如果你只想缩短等待时间,传 timeout 就够了。

错误模型概览

HTTP 状态码 SDK 错误类型 附加信息
401/403 UnauthorizedError codestatus
404 NotFoundError / NoMatchError codestatus
400 InvalidParameterError / InvalidParamsError codestatusdetails
429 ServiceBusyError codestatusretry_after_seconds(用于决定何时重试)
5xx InternalServerErrorError / ApiErrorError codestatusdetails
其他 4xx UapiError codestatusdetails

其他 SDK

语言 仓库地址
Go https://github.com/AxT-Team/uapi-sdk-go
Python(当前) https://github.com/AxT-Team/uapi-sdk-python
TypeScript https://github.com/AxT-Team/uapi-sdk-typescript
Browser (TypeScript/JavaScript) https://github.com/AxT-Team/uapi-browser-sdk
Java https://github.com/AxT-Team/uapi-sdk-java
PHP https://github.com/AxT-Team/uapi-sdk-php
C# https://github.com/AxT-Team/uapi-sdk-csharp
C++ https://github.com/AxT-Team/uapi-sdk-cpp
Rust https://github.com/AxT-Team/uapi-sdk-rust

文档

访问 UApi文档首页 并选择任意接口,向下滚动到 快速启动 区块即可看到最新的 Python 示例代码。

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

uapi_sdk_python-0.1.17.tar.gz (43.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

uapi_sdk_python-0.1.17-py3-none-any.whl (41.2 kB view details)

Uploaded Python 3

File details

Details for the file uapi_sdk_python-0.1.17.tar.gz.

File metadata

  • Download URL: uapi_sdk_python-0.1.17.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for uapi_sdk_python-0.1.17.tar.gz
Algorithm Hash digest
SHA256 3cbd603603e0139a943e5a720f41326056ed9e1ea17e83d60d6e18f764fbfa6b
MD5 730f5b9e7cb5027d6f4300f60fc473cb
BLAKE2b-256 ed62cf85782b52fc71f07b511fb41622d2b627815bbfcd468552e2ece5b8ded4

See more details on using hashes here.

File details

Details for the file uapi_sdk_python-0.1.17-py3-none-any.whl.

File metadata

File hashes

Hashes for uapi_sdk_python-0.1.17-py3-none-any.whl
Algorithm Hash digest
SHA256 ed14d4fb8b95b41b40239adeb7cee094fe1442f67ed72d8d1a539127cfd80372
MD5 88fc62614d16d7da2b4c47630152247b
BLAKE2b-256 a59c71461cf6d64b4f8edb9be7a045b3eb9bc3755690dcd2706632d0aa2c4dec

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page