okdata 0.1.0__py3-none-any.whl
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.
- okdata/__init__.py +28 -0
- okdata/_async_client.py +119 -0
- okdata/_base.py +88 -0
- okdata/_client.py +135 -0
- okdata/_errors.py +88 -0
- okdata/_generated/__init__.py +1 -0
- okdata/_generated/_async.py +7150 -0
- okdata/_generated/_endpoints.py +227 -0
- okdata/_generated/_errors.py +36 -0
- okdata/_generated/_models.py +1329 -0
- okdata/_generated/_sync.py +7150 -0
- okdata/_money.py +44 -0
- okdata/_paging.py +208 -0
- okdata/_request.py +74 -0
- okdata/_result.py +119 -0
- okdata/_transport.py +103 -0
- okdata/_types.py +123 -0
- okdata/_version.py +1 -0
- okdata/py.typed +0 -0
- okdata-0.1.0.dist-info/METADATA +143 -0
- okdata-0.1.0.dist-info/RECORD +23 -0
- okdata-0.1.0.dist-info/WHEEL +4 -0
- okdata-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: okdata
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python SDK for okdata: social data from Douyin, Xiaohongshu, WeChat, Bilibili, Weibo, TikTok, X, YouTube and more, for AI agents, paid per call. Typed methods per endpoint, sync and async, safe retries, paging with a spend limit.
|
|
5
|
+
Project-URL: Homepage, https://okdata.online/
|
|
6
|
+
Project-URL: Documentation, https://okdata.online/docs/sdk/
|
|
7
|
+
Project-URL: Endpoints, https://okdata.online/apis/
|
|
8
|
+
Project-URL: Pricing, https://okdata.online/pricing/
|
|
9
|
+
Project-URL: Source, https://github.com/okdataapi/okdata/tree/main/python
|
|
10
|
+
Project-URL: Issues, https://github.com/okdataapi/okdata/issues
|
|
11
|
+
Author-email: okdata <hello@okdata.online>
|
|
12
|
+
License-Expression: MIT
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Keywords: ai agents,bilibili,douyin,instagram,mcp,okdata,reddit,rednote,sdk,social data,social media api,tiktok,twitter,wechat,weibo,x,xiaohongshu,youtube
|
|
15
|
+
Classifier: Development Status :: 4 - Beta
|
|
16
|
+
Classifier: Intended Audience :: Developers
|
|
17
|
+
Classifier: Operating System :: OS Independent
|
|
18
|
+
Classifier: Programming Language :: Python :: 3
|
|
19
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
25
|
+
Classifier: Topic :: Internet :: WWW/HTTP
|
|
26
|
+
Classifier: Typing :: Typed
|
|
27
|
+
Requires-Python: >=3.9
|
|
28
|
+
Requires-Dist: httpx<1,>=0.25
|
|
29
|
+
Provides-Extra: dev
|
|
30
|
+
Requires-Dist: mypy>=1.8; extra == 'dev'
|
|
31
|
+
Requires-Dist: pytest>=7; extra == 'dev'
|
|
32
|
+
Provides-Extra: test
|
|
33
|
+
Requires-Dist: pytest>=7; extra == 'test'
|
|
34
|
+
Description-Content-Type: text/markdown
|
|
35
|
+
|
|
36
|
+
# okdata for Python
|
|
37
|
+
|
|
38
|
+
Social data for AI agents, paid per call: Douyin, Xiaohongshu, WeChat, Bilibili, Weibo, Kuaishou, Zhihu,
|
|
39
|
+
TikTok, X, YouTube, Instagram, Reddit and more, as one API with one envelope and one error format.
|
|
40
|
+
Every endpoint is a typed method generated from the okdata catalog, with its price in its docstring.
|
|
41
|
+
|
|
42
|
+
```sh
|
|
43
|
+
pip install okdata # Python 3.9+, one dependency (httpx)
|
|
44
|
+
export OKDATA_API_KEY=okd_...
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
No key yet? Sign up at [okdata.online](https://okdata.online/signup/?src=pypi-okdata)
|
|
48
|
+
(中文:[注册](https://okdata.online/zh/signup/?src=pypi-okdata)).
|
|
49
|
+
|
|
50
|
+
## First call
|
|
51
|
+
|
|
52
|
+
The Playground's Python tab shows the raw HTTP request; with the SDK the same call is:
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
from okdata import OkData
|
|
56
|
+
|
|
57
|
+
ok = OkData() # reads OKDATA_API_KEY; OkData("okd_...") works too
|
|
58
|
+
page = ok.douyin.videos.search(query="露营装备", sort="latest", max_price="0.05")
|
|
59
|
+
for row in page.items:
|
|
60
|
+
print(row["id"], row["metrics"]["likes"], row["text"][:60])
|
|
61
|
+
print("cost: $" + page.cost)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Parameters are flat and named as in the API (`query`, `id`, `url`, `cursor`, ...). Every method also
|
|
65
|
+
takes `view` (`compact` | `standard` | `full`, same price), `fields` (`["id", "text"]` or `"id,text"`),
|
|
66
|
+
`max_price` (sent as `X-Max-Price`: a call that could cost more is refused before it runs, never
|
|
67
|
+
charged), `idempotency_key` and `timeout`. Any endpoint also works by id:
|
|
68
|
+
`ok.call("weibo.trends.list")`, including ids newer than your SDK version.
|
|
69
|
+
|
|
70
|
+
What comes back: `Page` (list endpoints: `items`, `next_cursor`, `has_more`), `Item` (one object:
|
|
71
|
+
`item`) or `Batch` (`ids=[...]` on endpoints that take a list: `items`, `missing`). Each has `cost`,
|
|
72
|
+
`balance_after`, `request_id`, `result_status`, `replayed`, `warnings`, `meta` and the `raw` envelope.
|
|
73
|
+
Items are plain dicts, typed as `TypedDict`s (`Post`, `Account`, `Comment`, ...).
|
|
74
|
+
|
|
75
|
+
## Paging within a budget
|
|
76
|
+
|
|
77
|
+
```python
|
|
78
|
+
for page in ok.pages("douyin.videos.comments.list", id="7301234567890123456", max_pages=5, max_spend="0.01"):
|
|
79
|
+
...
|
|
80
|
+
|
|
81
|
+
items = ok.items("x.posts.search", query="claude code", max_items=200, max_spend="0.05")
|
|
82
|
+
rows = list(items)
|
|
83
|
+
print(items.spent, items.stop_reason) # "0.03", "max_items" | "max_spend" | "end" | "balance" | "max_pages"
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
Each page is a separate, separately charged call. Before each page the pager adds what that page could
|
|
87
|
+
cost at most (the endpoint's `max_charge`) and stops if the total would pass `max_spend`; each call also
|
|
88
|
+
carries `X-Max-Price` set to what is left, so the server refuses (free) anything dearer.
|
|
89
|
+
|
|
90
|
+
## Retries and idempotency
|
|
91
|
+
|
|
92
|
+
Every paid call gets an `Idempotency-Key`, reused by its retries, so a retry is never charged twice.
|
|
93
|
+
Retries follow the error body: `retry` `yes` / `same_key` are retried (after `retry_after_seconds` when
|
|
94
|
+
given; a wait longer than `max_retry_delay` raises instead), `once` gets one more try, `no` and
|
|
95
|
+
`after_fix` are never retried. Defaults: `max_retries=2`, `timeout=65` seconds per attempt.
|
|
96
|
+
|
|
97
|
+
## Errors
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from okdata import OkDataError
|
|
101
|
+
|
|
102
|
+
try:
|
|
103
|
+
ok.x.posts.get(id="1850000000000000000")
|
|
104
|
+
except OkDataError as err:
|
|
105
|
+
err.code, err.charged, err.retry, err.request_id # branch on code, never on message
|
|
106
|
+
err.message, err.message_zh, err.problems, err.param, err.reason, err.retry_after_seconds
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
`charged` is `False` for almost every error, `True` for a `not_found` the endpoint charges (`amount`
|
|
110
|
+
says how much) and `None` when it is not known yet (a lost answer, `settlement_unknown`): look it up
|
|
111
|
+
with `ok.calls.get(err.request_id)` or `ok.calls.by_key(err.idempotency_key)`. A lost connection raises
|
|
112
|
+
`OkDataConnectionError` (`connection_error` or `client_timeout`, `charged=None`). The codes are in
|
|
113
|
+
`okdata.ERROR_CODES` and at https://okdata.online/docs/errors/.
|
|
114
|
+
|
|
115
|
+
## Async
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import asyncio
|
|
119
|
+
from okdata import AsyncOkData
|
|
120
|
+
|
|
121
|
+
async def main():
|
|
122
|
+
async with AsyncOkData() as ok:
|
|
123
|
+
page = await ok.weibo.trends.list()
|
|
124
|
+
async for row in ok.items("douyin.videos.search", query="露营装备", max_spend="0.1"):
|
|
125
|
+
print(row["id"])
|
|
126
|
+
|
|
127
|
+
asyncio.run(main())
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Free routes
|
|
131
|
+
|
|
132
|
+
`ok.catalog()`, `ok.status()` (no key needed), `ok.account()` (balance, key limits, rate tier),
|
|
133
|
+
`ok.usage(group_by=["day", "capability"])`, `ok.calls.get(request_id)`, `ok.calls.result(request_id,
|
|
134
|
+
view="full")` (a result kept 24 h, read again for free) and `ok.calls.by_key(idempotency_key)`.
|
|
135
|
+
|
|
136
|
+
## Options
|
|
137
|
+
|
|
138
|
+
`OkData(api_key=None, *, base_url=None, timeout=65.0, max_retries=2, retry_base_delay=0.5,
|
|
139
|
+
max_retry_delay=20.0, source=None, end_user=None, user_agent=None, http_client=None)`. `base_url`
|
|
140
|
+
defaults to `OKDATA_BASE_URL`, then `https://api.okdata.online`. `source` and `end_user` are sent as
|
|
141
|
+
`X-Source` and `X-End-User` for your usage figures; every call carries `X-Entry: sdk`.
|
|
142
|
+
|
|
143
|
+
MIT licensed.
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
okdata/__init__.py,sha256=0sLJ57zWQ0p6xKnVxh-y9btJQT6NC14XmKM1_zlKSaY,1571
|
|
2
|
+
okdata/_async_client.py,sha256=_ElXfHOQu2U607NHd7LDuwb_fXD1CZDaIwUYldccQmI,5764
|
|
3
|
+
okdata/_base.py,sha256=F_xW-UzhM4qGChvXFhIc3t53VcoL4vQ0gGANVTlhFXI,3928
|
|
4
|
+
okdata/_client.py,sha256=0PnlBhDcrXatS2v0enYYNIjRA6kYlOHej_oUc7I0xis,6538
|
|
5
|
+
okdata/_errors.py,sha256=tV89YPmTdUjqQ_zuMryELAlW9lg8VmYFK4qYyCYI-SE,3966
|
|
6
|
+
okdata/_money.py,sha256=zyGW5FcJtdyUDZPGsMJRsRDBE9u-N7MBV70Qu6BVGig,1845
|
|
7
|
+
okdata/_paging.py,sha256=f1wUMBXXNwDsUQjMHNXoThmz2ffxnzVkTusYeK8ea0I,7720
|
|
8
|
+
okdata/_request.py,sha256=8gvgWuLOF9RqpswTSAUHvjvn049r9lhI6enaURniP5o,3005
|
|
9
|
+
okdata/_result.py,sha256=s5LzJWU3_jjkKrq6QN4cVdoRNeKARuD70tOcVLFQv_c,5155
|
|
10
|
+
okdata/_transport.py,sha256=GOwUZrsA6JCuSmb0uDcv80Yow_OWEpJhZS1aDSX2Gak,4426
|
|
11
|
+
okdata/_types.py,sha256=3GX3CA91f1LpsUSctUOCgp3X_5Ua_3HDNGhlJTmhzDc,3409
|
|
12
|
+
okdata/_version.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
|
|
13
|
+
okdata/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
14
|
+
okdata/_generated/__init__.py,sha256=Gdd8dIdKYPUhKwjVmCM4bhd7lbDNgc6GtC_uqvZkGWk,82
|
|
15
|
+
okdata/_generated/_async.py,sha256=dVVMWa9Tr7XGoNlz7zOCjvaCeMM0wlnvnvlH-IxeO0E,309971
|
|
16
|
+
okdata/_generated/_endpoints.py,sha256=hWOYHrhkfvX8lfezeDoQbVGLp6Jr7vP1YlkTecl0znI,62593
|
|
17
|
+
okdata/_generated/_errors.py,sha256=7iNDsASaofTToGkZpBoGMmHiLps-hryfYLhE5Fw8QwA,2013
|
|
18
|
+
okdata/_generated/_models.py,sha256=2md9jgfrdpp-1i2URS4HajSNV_MDYZcz_gkrBnOnx4I,54538
|
|
19
|
+
okdata/_generated/_sync.py,sha256=0FMgF9E6LtKea3pxJ9ttGswwqsrxxktpRINmeNgG8Lk,306219
|
|
20
|
+
okdata-0.1.0.dist-info/METADATA,sha256=uEjIsG7C_hgM8Y6-QkWIi3GbojoXphAzvygrX3JFd9Q,6466
|
|
21
|
+
okdata-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
22
|
+
okdata-0.1.0.dist-info/licenses/LICENSE,sha256=yT2xhW3vQqOuKoTF9Olce9I3wqb1yt_kFxBtjOOVEbE,1063
|
|
23
|
+
okdata-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 okdata
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|