uapi-sdk-python 0.1.1__tar.gz → 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/PKG-INFO +61 -9
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/README.md +60 -8
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/pyproject.toml +1 -1
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/uapi/client.py +26 -0
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/uapi_sdk_python.egg-info/PKG-INFO +61 -9
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/setup.cfg +0 -0
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/tests/test_client.py +0 -0
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/uapi/__init__.py +0 -0
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/uapi/errors.py +0 -0
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/uapi_sdk_python.egg-info/SOURCES.txt +0 -0
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/uapi_sdk_python.egg-info/dependency_links.txt +0 -0
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/uapi_sdk_python.egg-info/requires.txt +0 -0
- {uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/uapi_sdk_python.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: uapi-sdk-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Idiomatic UAPI SDK for Python
|
|
5
5
|
Author-email: UAPI <dev@uapis.cn>
|
|
6
6
|
Requires-Python: >=3.9
|
|
@@ -37,6 +37,9 @@ result = client.social.get_social_qq_userinfo(qq="10001")
|
|
|
37
37
|
print(result)
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
> [!TIP]
|
|
41
|
+
> 请使用与运行脚本相同的 Python 解释器安装依赖,例如执行 `python -m pip install uapi-sdk-python` 后再运行 `python main.py`。在 VS Code / Pyright 中若提示 “Import uapi could not be resolved”,将解释器切换到当前虚拟环境即可恢复补全。
|
|
42
|
+
|
|
40
43
|
## 特性
|
|
41
44
|
|
|
42
45
|
现在你不再需要反反复复的查阅文档了。
|
|
@@ -51,6 +54,54 @@ print(result)
|
|
|
51
54
|
|
|
52
55
|
如果你需要查看字段细节或内部逻辑,仓库中的 `./internal` 目录同步保留了由 `openapi-generator` 生成的完整结构体,随时可供参考。
|
|
53
56
|
|
|
57
|
+
## 进阶实践
|
|
58
|
+
|
|
59
|
+
### 缓存与幂等
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from functools import lru_cache
|
|
63
|
+
from uapi import UapiClient
|
|
64
|
+
|
|
65
|
+
client = UapiClient("https://uapis.cn/api/v1", token="<TOKEN>")
|
|
66
|
+
|
|
67
|
+
@lru_cache(maxsize=128)
|
|
68
|
+
def cached_lookup(qq: str):
|
|
69
|
+
return client.social.get_social_qq_userinfo(qq=qq)
|
|
70
|
+
|
|
71
|
+
user = cached_lookup("10001")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
也可以在 FastAPI / Django 项目里配合 Redis,将 SDK 的响应序列化后写入缓存,命中即直接返回。
|
|
75
|
+
|
|
76
|
+
### 注入自定义 httpx.Client
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import httpx
|
|
80
|
+
from httpx import Auth
|
|
81
|
+
from uapi import UapiClient
|
|
82
|
+
|
|
83
|
+
class StaticToken(Auth):
|
|
84
|
+
def __init__(self, token: str):
|
|
85
|
+
self.token = token
|
|
86
|
+
def auth_flow(self, request):
|
|
87
|
+
request.headers["Authorization"] = f"Bearer {self.token}"
|
|
88
|
+
yield request
|
|
89
|
+
|
|
90
|
+
http_client = httpx.Client(
|
|
91
|
+
timeout=5,
|
|
92
|
+
transport=httpx.HTTPTransport(retries=3),
|
|
93
|
+
event_hooks={"request": [lambda request: print("->", request.url)]},
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
client = UapiClient(
|
|
97
|
+
"https://uapis.cn/api/v1",
|
|
98
|
+
client=http_client,
|
|
99
|
+
auth=StaticToken("<TOKEN>"),
|
|
100
|
+
)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
通过自定义 `client` / `transport` / `auth`,可以无缝植入代理、重试策略或 APM 埋点。
|
|
104
|
+
|
|
54
105
|
## 错误模型概览
|
|
55
106
|
|
|
56
107
|
| HTTP 状态码 | SDK 错误类型 | 附加信息 |
|
|
@@ -66,17 +117,18 @@ print(result)
|
|
|
66
117
|
|
|
67
118
|
| 语言 | 仓库地址 |
|
|
68
119
|
|-------------|--------------------------------------------------------------|
|
|
69
|
-
| Go | https://github.com/AxT-Team/uapi-go
|
|
70
|
-
| Python(当前) | https://github.com/AxT-Team/uapi-python
|
|
71
|
-
| TypeScript| https://github.com/AxT-Team/uapi-typescript
|
|
120
|
+
| Go | https://github.com/AxT-Team/uapi-sdk-go |
|
|
121
|
+
| Python(当前) | https://github.com/AxT-Team/uapi-sdk-python |
|
|
122
|
+
| TypeScript| https://github.com/AxT-Team/uapi-sdk-typescript |
|
|
72
123
|
| Browser (TypeScript/JavaScript)| https://github.com/AxT-Team/uapi-browser-sdk |
|
|
73
|
-
| Java | https://github.com/AxT-Team/uapi-java
|
|
74
|
-
| PHP | https://github.com/AxT-Team/uapi-php
|
|
75
|
-
| C# | https://github.com/AxT-Team/uapi-csharp
|
|
76
|
-
| C++ | https://github.com/AxT-Team/uapi-cpp
|
|
77
|
-
| Rust | https://github.com/AxT-Team/uapi-rust
|
|
124
|
+
| Java | https://github.com/AxT-Team/uapi-sdk-java |
|
|
125
|
+
| PHP | https://github.com/AxT-Team/uapi-sdk-php |
|
|
126
|
+
| C# | https://github.com/AxT-Team/uapi-sdk-csharp |
|
|
127
|
+
| C++ | https://github.com/AxT-Team/uapi-sdk-cpp |
|
|
128
|
+
| Rust | https://github.com/AxT-Team/uapi-sdk-rust |
|
|
78
129
|
|
|
79
130
|
## 文档
|
|
80
131
|
|
|
81
132
|
访问 [UApi文档首页](https://uapis.cn/docs/introduction) 并选择任意接口,向下滚动到 **快速启动** 区块即可看到最新的 Python 示例代码。
|
|
82
133
|
|
|
134
|
+
|
|
@@ -23,6 +23,9 @@ result = client.social.get_social_qq_userinfo(qq="10001")
|
|
|
23
23
|
print(result)
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
+
> [!TIP]
|
|
27
|
+
> 请使用与运行脚本相同的 Python 解释器安装依赖,例如执行 `python -m pip install uapi-sdk-python` 后再运行 `python main.py`。在 VS Code / Pyright 中若提示 “Import uapi could not be resolved”,将解释器切换到当前虚拟环境即可恢复补全。
|
|
28
|
+
|
|
26
29
|
## 特性
|
|
27
30
|
|
|
28
31
|
现在你不再需要反反复复的查阅文档了。
|
|
@@ -37,6 +40,54 @@ print(result)
|
|
|
37
40
|
|
|
38
41
|
如果你需要查看字段细节或内部逻辑,仓库中的 `./internal` 目录同步保留了由 `openapi-generator` 生成的完整结构体,随时可供参考。
|
|
39
42
|
|
|
43
|
+
## 进阶实践
|
|
44
|
+
|
|
45
|
+
### 缓存与幂等
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from functools import lru_cache
|
|
49
|
+
from uapi import UapiClient
|
|
50
|
+
|
|
51
|
+
client = UapiClient("https://uapis.cn/api/v1", token="<TOKEN>")
|
|
52
|
+
|
|
53
|
+
@lru_cache(maxsize=128)
|
|
54
|
+
def cached_lookup(qq: str):
|
|
55
|
+
return client.social.get_social_qq_userinfo(qq=qq)
|
|
56
|
+
|
|
57
|
+
user = cached_lookup("10001")
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
也可以在 FastAPI / Django 项目里配合 Redis,将 SDK 的响应序列化后写入缓存,命中即直接返回。
|
|
61
|
+
|
|
62
|
+
### 注入自定义 httpx.Client
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
import httpx
|
|
66
|
+
from httpx import Auth
|
|
67
|
+
from uapi import UapiClient
|
|
68
|
+
|
|
69
|
+
class StaticToken(Auth):
|
|
70
|
+
def __init__(self, token: str):
|
|
71
|
+
self.token = token
|
|
72
|
+
def auth_flow(self, request):
|
|
73
|
+
request.headers["Authorization"] = f"Bearer {self.token}"
|
|
74
|
+
yield request
|
|
75
|
+
|
|
76
|
+
http_client = httpx.Client(
|
|
77
|
+
timeout=5,
|
|
78
|
+
transport=httpx.HTTPTransport(retries=3),
|
|
79
|
+
event_hooks={"request": [lambda request: print("->", request.url)]},
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
client = UapiClient(
|
|
83
|
+
"https://uapis.cn/api/v1",
|
|
84
|
+
client=http_client,
|
|
85
|
+
auth=StaticToken("<TOKEN>"),
|
|
86
|
+
)
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
通过自定义 `client` / `transport` / `auth`,可以无缝植入代理、重试策略或 APM 埋点。
|
|
90
|
+
|
|
40
91
|
## 错误模型概览
|
|
41
92
|
|
|
42
93
|
| HTTP 状态码 | SDK 错误类型 | 附加信息 |
|
|
@@ -52,17 +103,18 @@ print(result)
|
|
|
52
103
|
|
|
53
104
|
| 语言 | 仓库地址 |
|
|
54
105
|
|-------------|--------------------------------------------------------------|
|
|
55
|
-
| Go | https://github.com/AxT-Team/uapi-go
|
|
56
|
-
| Python(当前) | https://github.com/AxT-Team/uapi-python
|
|
57
|
-
| TypeScript| https://github.com/AxT-Team/uapi-typescript
|
|
106
|
+
| Go | https://github.com/AxT-Team/uapi-sdk-go |
|
|
107
|
+
| Python(当前) | https://github.com/AxT-Team/uapi-sdk-python |
|
|
108
|
+
| TypeScript| https://github.com/AxT-Team/uapi-sdk-typescript |
|
|
58
109
|
| Browser (TypeScript/JavaScript)| https://github.com/AxT-Team/uapi-browser-sdk |
|
|
59
|
-
| Java | https://github.com/AxT-Team/uapi-java
|
|
60
|
-
| PHP | https://github.com/AxT-Team/uapi-php
|
|
61
|
-
| C# | https://github.com/AxT-Team/uapi-csharp
|
|
62
|
-
| C++ | https://github.com/AxT-Team/uapi-cpp
|
|
63
|
-
| Rust | https://github.com/AxT-Team/uapi-rust
|
|
110
|
+
| Java | https://github.com/AxT-Team/uapi-sdk-java |
|
|
111
|
+
| PHP | https://github.com/AxT-Team/uapi-sdk-php |
|
|
112
|
+
| C# | https://github.com/AxT-Team/uapi-sdk-csharp |
|
|
113
|
+
| C++ | https://github.com/AxT-Team/uapi-sdk-cpp |
|
|
114
|
+
| Rust | https://github.com/AxT-Team/uapi-sdk-rust |
|
|
64
115
|
|
|
65
116
|
## 文档
|
|
66
117
|
|
|
67
118
|
访问 [UApi文档首页](https://uapis.cn/docs/introduction) 并选择任意接口,向下滚动到 **快速启动** 区块即可看到最新的 Python 示例代码。
|
|
68
119
|
|
|
120
|
+
|
|
@@ -1739,6 +1739,32 @@ class _TranslateApi:
|
|
|
1739
1739
|
|
|
1740
1740
|
return self._http.request("POST", path, params=params, json=body)
|
|
1741
1741
|
|
|
1742
|
+
def post_translate_stream(self, **kwargs):
|
|
1743
|
+
"""流式翻译(中英互译)
|
|
1744
|
+
想让翻译结果像打字机一样逐字显示出来?这个流式翻译接口能实现这种效果。
|
|
1745
|
+
|
|
1746
|
+
## 功能概述
|
|
1747
|
+
不同于传统翻译API一次性返回完整结果,这个接口会实时地、一个字一个字地把翻译内容推给你(就像ChatGPT回复消息那样),非常适合用在聊天应用、直播字幕等需要即时反馈的场景。
|
|
1748
|
+
|
|
1749
|
+
## 它能做什么
|
|
1750
|
+
- **中英互译**:支持中文和英文之间的双向翻译
|
|
1751
|
+
- **自动识别**:不确定源语言?设置为 `auto` 让我们自动检测
|
|
1752
|
+
- **逐字返回**:翻译结果会像打字机一样逐字流式返回,用户体验更流畅
|
|
1753
|
+
- **音频朗读**:部分翻译结果会附带音频链接,方便朗读
|
|
1754
|
+
|
|
1755
|
+
## 支持的语言
|
|
1756
|
+
目前专注于中英互译,支持以下选项:
|
|
1757
|
+
- `中文`(简体/繁体)
|
|
1758
|
+
- `英文`
|
|
1759
|
+
- `auto`(自动检测)
|
|
1760
|
+
"""
|
|
1761
|
+
params = {}
|
|
1762
|
+
body = None
|
|
1763
|
+
|
|
1764
|
+
path = "/translate/stream"
|
|
1765
|
+
|
|
1766
|
+
return self._http.request("POST", path, params=params, json=body)
|
|
1767
|
+
|
|
1742
1768
|
def post_translate_text(self, **kwargs):
|
|
1743
1769
|
"""多语言文本翻译
|
|
1744
1770
|
需要跨越语言的鸿沟进行交流?这个翻译接口是你可靠的'同声传译'。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: uapi-sdk-python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Idiomatic UAPI SDK for Python
|
|
5
5
|
Author-email: UAPI <dev@uapis.cn>
|
|
6
6
|
Requires-Python: >=3.9
|
|
@@ -37,6 +37,9 @@ result = client.social.get_social_qq_userinfo(qq="10001")
|
|
|
37
37
|
print(result)
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
> [!TIP]
|
|
41
|
+
> 请使用与运行脚本相同的 Python 解释器安装依赖,例如执行 `python -m pip install uapi-sdk-python` 后再运行 `python main.py`。在 VS Code / Pyright 中若提示 “Import uapi could not be resolved”,将解释器切换到当前虚拟环境即可恢复补全。
|
|
42
|
+
|
|
40
43
|
## 特性
|
|
41
44
|
|
|
42
45
|
现在你不再需要反反复复的查阅文档了。
|
|
@@ -51,6 +54,54 @@ print(result)
|
|
|
51
54
|
|
|
52
55
|
如果你需要查看字段细节或内部逻辑,仓库中的 `./internal` 目录同步保留了由 `openapi-generator` 生成的完整结构体,随时可供参考。
|
|
53
56
|
|
|
57
|
+
## 进阶实践
|
|
58
|
+
|
|
59
|
+
### 缓存与幂等
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from functools import lru_cache
|
|
63
|
+
from uapi import UapiClient
|
|
64
|
+
|
|
65
|
+
client = UapiClient("https://uapis.cn/api/v1", token="<TOKEN>")
|
|
66
|
+
|
|
67
|
+
@lru_cache(maxsize=128)
|
|
68
|
+
def cached_lookup(qq: str):
|
|
69
|
+
return client.social.get_social_qq_userinfo(qq=qq)
|
|
70
|
+
|
|
71
|
+
user = cached_lookup("10001")
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
也可以在 FastAPI / Django 项目里配合 Redis,将 SDK 的响应序列化后写入缓存,命中即直接返回。
|
|
75
|
+
|
|
76
|
+
### 注入自定义 httpx.Client
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
import httpx
|
|
80
|
+
from httpx import Auth
|
|
81
|
+
from uapi import UapiClient
|
|
82
|
+
|
|
83
|
+
class StaticToken(Auth):
|
|
84
|
+
def __init__(self, token: str):
|
|
85
|
+
self.token = token
|
|
86
|
+
def auth_flow(self, request):
|
|
87
|
+
request.headers["Authorization"] = f"Bearer {self.token}"
|
|
88
|
+
yield request
|
|
89
|
+
|
|
90
|
+
http_client = httpx.Client(
|
|
91
|
+
timeout=5,
|
|
92
|
+
transport=httpx.HTTPTransport(retries=3),
|
|
93
|
+
event_hooks={"request": [lambda request: print("->", request.url)]},
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
client = UapiClient(
|
|
97
|
+
"https://uapis.cn/api/v1",
|
|
98
|
+
client=http_client,
|
|
99
|
+
auth=StaticToken("<TOKEN>"),
|
|
100
|
+
)
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
通过自定义 `client` / `transport` / `auth`,可以无缝植入代理、重试策略或 APM 埋点。
|
|
104
|
+
|
|
54
105
|
## 错误模型概览
|
|
55
106
|
|
|
56
107
|
| HTTP 状态码 | SDK 错误类型 | 附加信息 |
|
|
@@ -66,17 +117,18 @@ print(result)
|
|
|
66
117
|
|
|
67
118
|
| 语言 | 仓库地址 |
|
|
68
119
|
|-------------|--------------------------------------------------------------|
|
|
69
|
-
| Go | https://github.com/AxT-Team/uapi-go
|
|
70
|
-
| Python(当前) | https://github.com/AxT-Team/uapi-python
|
|
71
|
-
| TypeScript| https://github.com/AxT-Team/uapi-typescript
|
|
120
|
+
| Go | https://github.com/AxT-Team/uapi-sdk-go |
|
|
121
|
+
| Python(当前) | https://github.com/AxT-Team/uapi-sdk-python |
|
|
122
|
+
| TypeScript| https://github.com/AxT-Team/uapi-sdk-typescript |
|
|
72
123
|
| Browser (TypeScript/JavaScript)| https://github.com/AxT-Team/uapi-browser-sdk |
|
|
73
|
-
| Java | https://github.com/AxT-Team/uapi-java
|
|
74
|
-
| PHP | https://github.com/AxT-Team/uapi-php
|
|
75
|
-
| C# | https://github.com/AxT-Team/uapi-csharp
|
|
76
|
-
| C++ | https://github.com/AxT-Team/uapi-cpp
|
|
77
|
-
| Rust | https://github.com/AxT-Team/uapi-rust
|
|
124
|
+
| Java | https://github.com/AxT-Team/uapi-sdk-java |
|
|
125
|
+
| PHP | https://github.com/AxT-Team/uapi-sdk-php |
|
|
126
|
+
| C# | https://github.com/AxT-Team/uapi-sdk-csharp |
|
|
127
|
+
| C++ | https://github.com/AxT-Team/uapi-sdk-cpp |
|
|
128
|
+
| Rust | https://github.com/AxT-Team/uapi-sdk-rust |
|
|
78
129
|
|
|
79
130
|
## 文档
|
|
80
131
|
|
|
81
132
|
访问 [UApi文档首页](https://uapis.cn/docs/introduction) 并选择任意接口,向下滚动到 **快速启动** 区块即可看到最新的 Python 示例代码。
|
|
82
133
|
|
|
134
|
+
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{uapi_sdk_python-0.1.1 → uapi_sdk_python-0.1.2}/uapi_sdk_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|