uapi-sdk-python 0.1.13__tar.gz → 0.1.15__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: uapi-sdk-python
3
- Version: 0.1.13
3
+ Version: 0.1.15
4
4
  Summary: Idiomatic UAPI SDK for Python
5
5
  Author-email: UAPI <dev@uapis.cn>
6
6
  Requires-Python: >=3.9
@@ -32,7 +32,7 @@ pip install uapi-sdk-python
32
32
  ```python
33
33
  from uapi import UapiClient
34
34
 
35
- client = UapiClient("https://uapis.cn/api/v1")
35
+ client = UapiClient("https://uapis.cn", "YOUR_API_KEY")
36
36
  result = client.social.get_social_qq_userinfo(qq="10001")
37
37
  print(result)
38
38
  ```
@@ -62,7 +62,7 @@ print(result)
62
62
  from functools import lru_cache
63
63
  from uapi import UapiClient
64
64
 
65
- client = UapiClient("https://uapis.cn/api/v1", token="<TOKEN>")
65
+ client = UapiClient("https://uapis.cn", token="YOUR_API_KEY")
66
66
 
67
67
  @lru_cache(maxsize=128)
68
68
  def cached_lookup(qq: str):
@@ -73,34 +73,19 @@ user = cached_lookup("10001")
73
73
 
74
74
  也可以在 FastAPI / Django 项目里配合 Redis,将 SDK 的响应序列化后写入缓存,命中即直接返回。
75
75
 
76
- ### 注入自定义 httpx.Client
76
+ ### 调整超时与环境
77
77
 
78
78
  ```python
79
- import httpx
80
- from httpx import Auth
81
79
  from uapi import UapiClient
82
80
 
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
81
  client = UapiClient(
97
- "https://uapis.cn/api/v1",
98
- client=http_client,
99
- auth=StaticToken("<TOKEN>"),
82
+ "https://uapis.cn",
83
+ token="YOUR_API_KEY",
84
+ timeout=5.0,
100
85
  )
101
86
  ```
102
87
 
103
- 通过自定义 `client` / `transport` / `auth`,可以无缝植入代理、重试策略或 APM 埋点。
88
+ 如果你需要切换到别的环境,直接改 `base_url` 就可以;如果你只想缩短等待时间,传 `timeout` 就够了。
104
89
 
105
90
  ## 错误模型概览
106
91
 
@@ -18,7 +18,7 @@ pip install uapi-sdk-python
18
18
  ```python
19
19
  from uapi import UapiClient
20
20
 
21
- client = UapiClient("https://uapis.cn/api/v1")
21
+ client = UapiClient("https://uapis.cn", "YOUR_API_KEY")
22
22
  result = client.social.get_social_qq_userinfo(qq="10001")
23
23
  print(result)
24
24
  ```
@@ -48,7 +48,7 @@ print(result)
48
48
  from functools import lru_cache
49
49
  from uapi import UapiClient
50
50
 
51
- client = UapiClient("https://uapis.cn/api/v1", token="<TOKEN>")
51
+ client = UapiClient("https://uapis.cn", token="YOUR_API_KEY")
52
52
 
53
53
  @lru_cache(maxsize=128)
54
54
  def cached_lookup(qq: str):
@@ -59,34 +59,19 @@ user = cached_lookup("10001")
59
59
 
60
60
  也可以在 FastAPI / Django 项目里配合 Redis,将 SDK 的响应序列化后写入缓存,命中即直接返回。
61
61
 
62
- ### 注入自定义 httpx.Client
62
+ ### 调整超时与环境
63
63
 
64
64
  ```python
65
- import httpx
66
- from httpx import Auth
67
65
  from uapi import UapiClient
68
66
 
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
67
  client = UapiClient(
83
- "https://uapis.cn/api/v1",
84
- client=http_client,
85
- auth=StaticToken("<TOKEN>"),
68
+ "https://uapis.cn",
69
+ token="YOUR_API_KEY",
70
+ timeout=5.0,
86
71
  )
87
72
  ```
88
73
 
89
- 通过自定义 `client` / `transport` / `auth`,可以无缝植入代理、重试策略或 APM 埋点。
74
+ 如果你需要切换到别的环境,直接改 `base_url` 就可以;如果你只想缩短等待时间,传 `timeout` 就够了。
90
75
 
91
76
  ## 错误模型概览
92
77
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "uapi-sdk-python"
7
- version = "0.1.13"
7
+ version = "0.1.15"
8
8
  description = "Idiomatic UAPI SDK for Python"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"