langchain-dataxapi 0.1.0__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.
- langchain_dataxapi-0.1.0/.gitignore +7 -0
- langchain_dataxapi-0.1.0/LICENSE +21 -0
- langchain_dataxapi-0.1.0/PKG-INFO +232 -0
- langchain_dataxapi-0.1.0/README.md +211 -0
- langchain_dataxapi-0.1.0/langchain_dataxapi/__init__.py +55 -0
- langchain_dataxapi-0.1.0/langchain_dataxapi/_client.py +226 -0
- langchain_dataxapi-0.1.0/langchain_dataxapi/endpoint_tools.py +495 -0
- langchain_dataxapi-0.1.0/langchain_dataxapi/py.typed +0 -0
- langchain_dataxapi-0.1.0/langchain_dataxapi/toolkits.py +55 -0
- langchain_dataxapi-0.1.0/langchain_dataxapi/tools.py +258 -0
- langchain_dataxapi-0.1.0/pyproject.toml +65 -0
- langchain_dataxapi-0.1.0/scripts/generate_tools.py +263 -0
- langchain_dataxapi-0.1.0/tests/__init__.py +0 -0
- langchain_dataxapi-0.1.0/tests/integration_tests/__init__.py +0 -0
- langchain_dataxapi-0.1.0/tests/integration_tests/test_compile.py +6 -0
- langchain_dataxapi-0.1.0/tests/integration_tests/test_find.py +55 -0
- langchain_dataxapi-0.1.0/tests/integration_tests/test_paid.py +38 -0
- langchain_dataxapi-0.1.0/tests/unit_tests/__init__.py +0 -0
- langchain_dataxapi-0.1.0/tests/unit_tests/conftest.py +77 -0
- langchain_dataxapi-0.1.0/tests/unit_tests/test_client.py +108 -0
- langchain_dataxapi-0.1.0/tests/unit_tests/test_imports.py +31 -0
- langchain_dataxapi-0.1.0/tests/unit_tests/test_standard.py +49 -0
- langchain_dataxapi-0.1.0/tests/unit_tests/test_tools.py +222 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aurevant LLC
|
|
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.
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: langchain-dataxapi
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: LangChain tools for DataXAPI: public data from Douyin, Xiaohongshu (RedNote), WeChat, Weibo, Bilibili, Zhihu, Kuaishou, TikTok, YouTube, X and Reddit for agents.
|
|
5
|
+
Project-URL: Homepage, https://dataxapi.com/?ref=langchain
|
|
6
|
+
Project-URL: Documentation, https://github.com/data-x-api/langchain-dataxapi#readme
|
|
7
|
+
Project-URL: Repository, https://github.com/data-x-api/langchain-dataxapi
|
|
8
|
+
Project-URL: Issues, https://github.com/data-x-api/langchain-dataxapi/issues
|
|
9
|
+
Author-email: DataXAPI <support@dataxapi.com>
|
|
10
|
+
License-Expression: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Keywords: agents,bilibili,douyin,langchain,langgraph,rednote,social media,tiktok,toolkit,tools,wechat,weibo,xiaohongshu,youtube
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
16
|
+
Classifier: Typing :: Typed
|
|
17
|
+
Requires-Python: <4.0,>=3.10
|
|
18
|
+
Requires-Dist: httpx<1.0,>=0.27
|
|
19
|
+
Requires-Dist: langchain-core<2.0.0,>=0.3.60
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
|
|
22
|
+
# langchain-dataxapi
|
|
23
|
+
|
|
24
|
+
LangChain tools for [DataXAPI](https://dataxapi.com/?ref=langchain): public data from Douyin, Xiaohongshu (RedNote), WeChat Official Accounts, WeChat Channels, WeChat Search, Weibo, Bilibili, Zhihu and Kuaishou, plus Douyin's trend index, TikTok, YouTube, X and Reddit, for LangChain and LangGraph agents.
|
|
25
|
+
|
|
26
|
+
- **One key, 237 endpoints.** Twelve ready tools for the endpoints DataXAPI's customers call most, plus `dataxapi_find` (free) and `dataxapi_call`, which reach every endpoint.
|
|
27
|
+
- **No sign-in to your own platform account**, no cookies, no QR login.
|
|
28
|
+
- **Pay per call; errors are not charged.** Each tool's description states its price, and every answer says what that call cost (`billing.amount`, US dollars).
|
|
29
|
+
- **Free trial: up to 333 calls, no card.** Top up from $10; the balance does not expire.
|
|
30
|
+
|
|
31
|
+
中文说明见[下文](#中文说明)。
|
|
32
|
+
|
|
33
|
+
## Installation
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
pip install -U langchain-dataxapi
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Credentials
|
|
40
|
+
|
|
41
|
+
Create a key at <https://dataxapi.com/console/keys/?ref=langchain> (it starts with `dx_`) and set it:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
export DATAXAPI_API_KEY="dx_..."
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Or pass it to a tool or the toolkit: `DataXAPIToolkit(api_key="dx_...")`. `dataxapi_find` needs no key.
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from langchain_dataxapi import DataXAPIXiaohongshuNoteSearch
|
|
53
|
+
|
|
54
|
+
tool = DataXAPIXiaohongshuNoteSearch()
|
|
55
|
+
print(tool.invoke({"query": "露营", "sort": "popular"}))
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
The answer is a JSON string:
|
|
59
|
+
|
|
60
|
+
```json
|
|
61
|
+
{
|
|
62
|
+
"endpoint": "xiaohongshu.notes.search",
|
|
63
|
+
"data": {"items": [{"id": "…", "title": "…", "author": {"…": "…"}, "metrics": {"likes": 1024, "…": "…"}}]},
|
|
64
|
+
"page": {"next_cursor": "…", "has_more": true},
|
|
65
|
+
"billing": {"amount": "0.02", "currency": "USD", "balance_after": "9.98"},
|
|
66
|
+
"request_id": "…"
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
For the next page, call again with `cursor` set to `page.next_cursor`; each page is charged on its own.
|
|
71
|
+
|
|
72
|
+
## Use in an agent
|
|
73
|
+
|
|
74
|
+
`create_agent` builds a LangGraph agent. Give it the whole toolkit:
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from langchain.agents import create_agent
|
|
78
|
+
from langchain_dataxapi import DataXAPIToolkit
|
|
79
|
+
|
|
80
|
+
tools = DataXAPIToolkit().get_tools()
|
|
81
|
+
agent = create_agent(
|
|
82
|
+
model="claude-sonnet-4-6",
|
|
83
|
+
tools=tools,
|
|
84
|
+
system_prompt="You research Chinese and global social media with the DataXAPI tools. Cite links.",
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
result = agent.invoke(
|
|
88
|
+
{
|
|
89
|
+
"messages": [
|
|
90
|
+
{
|
|
91
|
+
"role": "user",
|
|
92
|
+
"content": "What do people on Xiaohongshu and Douyin say about camping coffee gear this week? "
|
|
93
|
+
"Pick the three most liked posts and summarize their top comments.",
|
|
94
|
+
}
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
)
|
|
98
|
+
print(result["messages"][-1].content)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
The agent searches with `dataxapi_xiaohongshu_notes_search` and `dataxapi_douyin_videos_search`, then reads comments with `dataxapi_xiaohongshu_notes_comments_list` and `dataxapi_douyin_videos_comments_list`. For anything without a named tool (a Bilibili user's profile, Weibo hot searches, Zhihu answers), it describes the need to `dataxapi_find`, gets the endpoint ID and parameters, and calls it with `dataxapi_call`.
|
|
102
|
+
|
|
103
|
+
To keep the tool list short, give the agent only the two general tools:
|
|
104
|
+
|
|
105
|
+
```python
|
|
106
|
+
tools = DataXAPIToolkit(endpoint_tools=False).get_tools() # dataxapi_find and dataxapi_call
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
A runnable script is in [examples/agent.py](examples/agent.py).
|
|
110
|
+
|
|
111
|
+
## Tools
|
|
112
|
+
|
|
113
|
+
<!-- tools:start -->
|
|
114
|
+
| Tool | Class | What it returns | Price |
|
|
115
|
+
|---|---|---|---|
|
|
116
|
+
| `dataxapi_find` | `DataXAPIFind` | Endpoints for a need described in plain words, with price and parameters | free |
|
|
117
|
+
| `dataxapi_call` | `DataXAPICall` | Any DataXAPI endpoint by its ID | that endpoint's price |
|
|
118
|
+
| `dataxapi_xiaohongshu_notes_search` | `DataXAPIXiaohongshuNoteSearch` | Search Xiaohongshu notes by terms: title, text, author, engagement counts, images, and a link that opens | $0.02 per call |
|
|
119
|
+
| `dataxapi_douyin_videos_search` | `DataXAPIDouyinVideoSearch` | Search Douyin videos by terms, a page at a time, sorted by relevance, newest or most liked and filtered by time posted: caption, author with follower count, engagement counts | $0.02 per call |
|
|
120
|
+
| `dataxapi_wechat_mp_accounts_articles_list` | `DataXAPIWeChatOfficialAccountArticles` | Get a page of the articles a WeChat Official Account published, newest first: title, digest, link, time published | $0.02 per call |
|
|
121
|
+
| `dataxapi_douyin_videos_comments_list` | `DataXAPIDouyinVideoComments` | Get a page of comments on a Douyin video: text, commenter, likes, reply count, time posted | $0.002 per call |
|
|
122
|
+
| `dataxapi_douyin_videos_metrics` | `DataXAPIDouyinVideoMetrics` | Get a Douyin video's counts as of now, by its ID: plays and likes | $0.002 per call |
|
|
123
|
+
| `dataxapi_wechat_mp_articles_get` | `DataXAPIWeChatArticle` | Get one WeChat Official Account article by its link: title, text, time published, the account's name and IDs | $0.02 per call |
|
|
124
|
+
| `dataxapi_douyin_index_keywords_history` | `DataXAPIDouyinKeywordTrend` | Get the day-by-day search index and composite index of a keyword, or of one to five keywords at once, on Douyin over a date range, from the Douyin index, with the daily averages of the period, of the one before and of a year earlier | $0.006 per call |
|
|
125
|
+
| `dataxapi_wechat_posts_search` | `DataXAPIWeChatSearch` | Get a page of WeChat Search results for search terms: Official Account articles and Channels videos mixed, each saying in type whether it is an article or a video; by relevance, newest or hottest, filtered by time posted, or articles only or videos only: title or description, the source account's name, time published, an article's link (with a band of reads on some), a video's likes and saves | $0.02 per call |
|
|
126
|
+
| `dataxapi_wechat_channels_videos_search` | `DataXAPIWeChatChannelsVideoSearch` | Get a page of WeChat Channels videos for search terms through WeChat Search, by relevance, newest or hottest, filtered by time posted: description, the account's name and avatar, time published, likes and saves, length, cover | $0.02 per call |
|
|
127
|
+
| `dataxapi_xiaohongshu_notes_comments_list` | `DataXAPIXiaohongshuNoteComments` | Get a page of top-level comments on a Xiaohongshu note by ID or link, newest first or hottest first: text, commenter, likes, reply count, time posted | $0.02 per call |
|
|
128
|
+
| `dataxapi_tiktok_videos_search` | `DataXAPITikTokVideoSearch` | Search TikTok videos by keyword, 30 a page; sort by relevance, likes or time posted, and limit how recently they were posted | $0.002 per call |
|
|
129
|
+
| `dataxapi_youtube_videos_transcript_get` | `DataXAPIYouTubeTranscript` | Get the transcript of a YouTube video by ID or link: the whole text and timed segments | $0.002 per call |
|
|
130
|
+
<!-- tools:end -->
|
|
131
|
+
|
|
132
|
+
Live prices are on each endpoint's page at [dataxapi.com/apis](https://dataxapi.com/apis/?ref=langchain).
|
|
133
|
+
|
|
134
|
+
### Find and call any endpoint
|
|
135
|
+
|
|
136
|
+
```python
|
|
137
|
+
from langchain_dataxapi import DataXAPICall, DataXAPIFind
|
|
138
|
+
|
|
139
|
+
DataXAPIFind().invoke({"query": "bilibili user profile"})
|
|
140
|
+
# {"matches": [{"endpoint": "bilibili.users.get", "price_usd": "0.002", "example_params": {...}, ...}], ...}
|
|
141
|
+
|
|
142
|
+
DataXAPICall().invoke({"endpoint": "bilibili.users.get", "params": {"id": "8047632"}})
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
`params` may be an object or a JSON string. Lists such as `keywords` are sent as a JSON body.
|
|
146
|
+
|
|
147
|
+
### Errors
|
|
148
|
+
|
|
149
|
+
An error comes back as the tool's answer, so an agent can read it and correct itself, for example:
|
|
150
|
+
|
|
151
|
+
```text
|
|
152
|
+
DataXAPI error invalid_params: A parameter is invalid. Nothing was charged. Fix the request before trying again. Request ID: ….
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
It names the error code, whether anything was charged and whether to retry. Pass `handle_tool_error=False` to raise `ToolException` instead. Error codes: [dataxapi.com/docs](https://dataxapi.com/docs/?ref=langchain).
|
|
156
|
+
|
|
157
|
+
### Async
|
|
158
|
+
|
|
159
|
+
Every tool supports `ainvoke`:
|
|
160
|
+
|
|
161
|
+
```python
|
|
162
|
+
await DataXAPIDouyinVideoSearch().ainvoke({"query": "露营"})
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
## Development
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
uv sync --all-groups
|
|
169
|
+
make test # unit tests, HTTP mocked, network off; includes langchain-tests' ToolsUnitTests
|
|
170
|
+
make integration_test # live and free: dataxapi_find only. Paid tests need DATAXAPI_API_KEY and DATAXAPI_RUN_PAID=1
|
|
171
|
+
make generate # rewrite the endpoint tools and the tables from the live catalog
|
|
172
|
+
make lint
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The endpoint tools in `langchain_dataxapi/endpoint_tools.py` are written by `scripts/generate_tools.py` from the free catalog at <https://api.dataxapi.com/v1/catalog>: names, argument schemas, allowed values and prices. Do not edit that file by hand.
|
|
176
|
+
|
|
177
|
+
## 中文说明
|
|
178
|
+
|
|
179
|
+
`langchain-dataxapi` 让 LangChain、LangGraph 智能体直接取抖音、小红书、微信公众号、视频号、微信搜一搜、微博、B 站、知乎、快手、巨量算数,以及 TikTok、YouTube、X、Reddit 的公开数据。
|
|
180
|
+
|
|
181
|
+
- 一个 Key 调全部 237 个接口:12 个常用接口各有现成工具,另有免费的“找接口”(`dataxapi_find`)和“调用任意接口”(`dataxapi_call`)。
|
|
182
|
+
- 不用登录你自己的平台账号,不要 Cookie、不扫码。
|
|
183
|
+
- 按次计费,出错不收费;每个工具的说明写了价格,每次返回都带这次花了多少(`billing.amount`,美元)。
|
|
184
|
+
- 免费试用最多 333 次,不用绑卡;最低充 $10,余额不过期。
|
|
185
|
+
|
|
186
|
+
安装与设置:
|
|
187
|
+
|
|
188
|
+
```bash
|
|
189
|
+
pip install -U langchain-dataxapi
|
|
190
|
+
export DATAXAPI_API_KEY="dx_..." # 在 https://dataxapi.com/console/keys/ 创建
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
from langchain.agents import create_agent
|
|
195
|
+
from langchain_dataxapi import DataXAPIToolkit
|
|
196
|
+
|
|
197
|
+
agent = create_agent(model="claude-sonnet-4-6", tools=DataXAPIToolkit().get_tools())
|
|
198
|
+
question = "这周小红书上关于露营咖啡的笔记里,点赞最多的三篇讲了什么?评论区怎么说?"
|
|
199
|
+
agent.invoke({"messages": [{"role": "user", "content": question}]})
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
<!-- tools-zh:start -->
|
|
203
|
+
| 工具 | 类名 | 拿到什么 | 价格 |
|
|
204
|
+
|---|---|---|---|
|
|
205
|
+
| `dataxapi_find` | `DataXAPIFind` | 用一句话描述要的数据,列出能用的接口、价格和参数 | 免费 |
|
|
206
|
+
| `dataxapi_call` | `DataXAPICall` | 用接口编号加参数调用全部接口里的任何一个 | 按该接口的价格 |
|
|
207
|
+
| `dataxapi_xiaohongshu_notes_search` | `DataXAPIXiaohongshuNoteSearch` | 小红书笔记搜索 | $0.02 一次,出错不收费 |
|
|
208
|
+
| `dataxapi_douyin_videos_search` | `DataXAPIDouyinVideoSearch` | 抖音视频搜索 | $0.02 一次,出错不收费 |
|
|
209
|
+
| `dataxapi_wechat_mp_accounts_articles_list` | `DataXAPIWeChatOfficialAccountArticles` | 微信公众号文章列表 | $0.02 一次,出错不收费 |
|
|
210
|
+
| `dataxapi_douyin_videos_comments_list` | `DataXAPIDouyinVideoComments` | 抖音视频评论 | $0.002 一次,出错不收费 |
|
|
211
|
+
| `dataxapi_douyin_videos_metrics` | `DataXAPIDouyinVideoMetrics` | 抖音视频播放量 | $0.002 一次,出错不收费 |
|
|
212
|
+
| `dataxapi_wechat_mp_articles_get` | `DataXAPIWeChatArticle` | 微信公众号文章详情 | $0.02 一次,出错不收费 |
|
|
213
|
+
| `dataxapi_douyin_index_keywords_history` | `DataXAPIDouyinKeywordTrend` | 抖音巨量算数关键词热度趋势 | $0.006 一次,出错不收费 |
|
|
214
|
+
| `dataxapi_wechat_posts_search` | `DataXAPIWeChatSearch` | 微信搜一搜综合搜索 | $0.02 一次,出错不收费 |
|
|
215
|
+
| `dataxapi_wechat_channels_videos_search` | `DataXAPIWeChatChannelsVideoSearch` | 微信搜一搜视频号视频搜索 | $0.02 一次,出错不收费 |
|
|
216
|
+
| `dataxapi_xiaohongshu_notes_comments_list` | `DataXAPIXiaohongshuNoteComments` | 小红书笔记评论 | $0.02 一次,出错不收费 |
|
|
217
|
+
| `dataxapi_tiktok_videos_search` | `DataXAPITikTokVideoSearch` | TikTok 视频搜索 | $0.002 一次,出错不收费 |
|
|
218
|
+
| `dataxapi_youtube_videos_transcript_get` | `DataXAPIYouTubeTranscript` | YouTube 视频字幕 | $0.002 一次,出错不收费 |
|
|
219
|
+
<!-- tools-zh:end -->
|
|
220
|
+
|
|
221
|
+
翻页:把上一次返回的 `page.next_cursor` 作为 `cursor` 再调一次,每页单独计费。出错时工具返回一段文字,写明错误码、有没有收费、要不要重试,智能体可以据此自己改正。
|
|
222
|
+
|
|
223
|
+
## Links
|
|
224
|
+
|
|
225
|
+
- Endpoints and prices: <https://dataxapi.com/apis/?ref=langchain>
|
|
226
|
+
- API docs: <https://dataxapi.com/docs/?ref=langchain>
|
|
227
|
+
- Catalog for AI tools: <https://dataxapi.com/llms-full.txt>
|
|
228
|
+
- Support: support@dataxapi.com
|
|
229
|
+
|
|
230
|
+
## License
|
|
231
|
+
|
|
232
|
+
MIT
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
# langchain-dataxapi
|
|
2
|
+
|
|
3
|
+
LangChain tools for [DataXAPI](https://dataxapi.com/?ref=langchain): public data from Douyin, Xiaohongshu (RedNote), WeChat Official Accounts, WeChat Channels, WeChat Search, Weibo, Bilibili, Zhihu and Kuaishou, plus Douyin's trend index, TikTok, YouTube, X and Reddit, for LangChain and LangGraph agents.
|
|
4
|
+
|
|
5
|
+
- **One key, 237 endpoints.** Twelve ready tools for the endpoints DataXAPI's customers call most, plus `dataxapi_find` (free) and `dataxapi_call`, which reach every endpoint.
|
|
6
|
+
- **No sign-in to your own platform account**, no cookies, no QR login.
|
|
7
|
+
- **Pay per call; errors are not charged.** Each tool's description states its price, and every answer says what that call cost (`billing.amount`, US dollars).
|
|
8
|
+
- **Free trial: up to 333 calls, no card.** Top up from $10; the balance does not expire.
|
|
9
|
+
|
|
10
|
+
中文说明见[下文](#中文说明)。
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
pip install -U langchain-dataxapi
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Credentials
|
|
19
|
+
|
|
20
|
+
Create a key at <https://dataxapi.com/console/keys/?ref=langchain> (it starts with `dx_`) and set it:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
export DATAXAPI_API_KEY="dx_..."
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or pass it to a tool or the toolkit: `DataXAPIToolkit(api_key="dx_...")`. `dataxapi_find` needs no key.
|
|
27
|
+
|
|
28
|
+
## Quick start
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from langchain_dataxapi import DataXAPIXiaohongshuNoteSearch
|
|
32
|
+
|
|
33
|
+
tool = DataXAPIXiaohongshuNoteSearch()
|
|
34
|
+
print(tool.invoke({"query": "露营", "sort": "popular"}))
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The answer is a JSON string:
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{
|
|
41
|
+
"endpoint": "xiaohongshu.notes.search",
|
|
42
|
+
"data": {"items": [{"id": "…", "title": "…", "author": {"…": "…"}, "metrics": {"likes": 1024, "…": "…"}}]},
|
|
43
|
+
"page": {"next_cursor": "…", "has_more": true},
|
|
44
|
+
"billing": {"amount": "0.02", "currency": "USD", "balance_after": "9.98"},
|
|
45
|
+
"request_id": "…"
|
|
46
|
+
}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
For the next page, call again with `cursor` set to `page.next_cursor`; each page is charged on its own.
|
|
50
|
+
|
|
51
|
+
## Use in an agent
|
|
52
|
+
|
|
53
|
+
`create_agent` builds a LangGraph agent. Give it the whole toolkit:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from langchain.agents import create_agent
|
|
57
|
+
from langchain_dataxapi import DataXAPIToolkit
|
|
58
|
+
|
|
59
|
+
tools = DataXAPIToolkit().get_tools()
|
|
60
|
+
agent = create_agent(
|
|
61
|
+
model="claude-sonnet-4-6",
|
|
62
|
+
tools=tools,
|
|
63
|
+
system_prompt="You research Chinese and global social media with the DataXAPI tools. Cite links.",
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
result = agent.invoke(
|
|
67
|
+
{
|
|
68
|
+
"messages": [
|
|
69
|
+
{
|
|
70
|
+
"role": "user",
|
|
71
|
+
"content": "What do people on Xiaohongshu and Douyin say about camping coffee gear this week? "
|
|
72
|
+
"Pick the three most liked posts and summarize their top comments.",
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
print(result["messages"][-1].content)
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
The agent searches with `dataxapi_xiaohongshu_notes_search` and `dataxapi_douyin_videos_search`, then reads comments with `dataxapi_xiaohongshu_notes_comments_list` and `dataxapi_douyin_videos_comments_list`. For anything without a named tool (a Bilibili user's profile, Weibo hot searches, Zhihu answers), it describes the need to `dataxapi_find`, gets the endpoint ID and parameters, and calls it with `dataxapi_call`.
|
|
81
|
+
|
|
82
|
+
To keep the tool list short, give the agent only the two general tools:
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
tools = DataXAPIToolkit(endpoint_tools=False).get_tools() # dataxapi_find and dataxapi_call
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
A runnable script is in [examples/agent.py](examples/agent.py).
|
|
89
|
+
|
|
90
|
+
## Tools
|
|
91
|
+
|
|
92
|
+
<!-- tools:start -->
|
|
93
|
+
| Tool | Class | What it returns | Price |
|
|
94
|
+
|---|---|---|---|
|
|
95
|
+
| `dataxapi_find` | `DataXAPIFind` | Endpoints for a need described in plain words, with price and parameters | free |
|
|
96
|
+
| `dataxapi_call` | `DataXAPICall` | Any DataXAPI endpoint by its ID | that endpoint's price |
|
|
97
|
+
| `dataxapi_xiaohongshu_notes_search` | `DataXAPIXiaohongshuNoteSearch` | Search Xiaohongshu notes by terms: title, text, author, engagement counts, images, and a link that opens | $0.02 per call |
|
|
98
|
+
| `dataxapi_douyin_videos_search` | `DataXAPIDouyinVideoSearch` | Search Douyin videos by terms, a page at a time, sorted by relevance, newest or most liked and filtered by time posted: caption, author with follower count, engagement counts | $0.02 per call |
|
|
99
|
+
| `dataxapi_wechat_mp_accounts_articles_list` | `DataXAPIWeChatOfficialAccountArticles` | Get a page of the articles a WeChat Official Account published, newest first: title, digest, link, time published | $0.02 per call |
|
|
100
|
+
| `dataxapi_douyin_videos_comments_list` | `DataXAPIDouyinVideoComments` | Get a page of comments on a Douyin video: text, commenter, likes, reply count, time posted | $0.002 per call |
|
|
101
|
+
| `dataxapi_douyin_videos_metrics` | `DataXAPIDouyinVideoMetrics` | Get a Douyin video's counts as of now, by its ID: plays and likes | $0.002 per call |
|
|
102
|
+
| `dataxapi_wechat_mp_articles_get` | `DataXAPIWeChatArticle` | Get one WeChat Official Account article by its link: title, text, time published, the account's name and IDs | $0.02 per call |
|
|
103
|
+
| `dataxapi_douyin_index_keywords_history` | `DataXAPIDouyinKeywordTrend` | Get the day-by-day search index and composite index of a keyword, or of one to five keywords at once, on Douyin over a date range, from the Douyin index, with the daily averages of the period, of the one before and of a year earlier | $0.006 per call |
|
|
104
|
+
| `dataxapi_wechat_posts_search` | `DataXAPIWeChatSearch` | Get a page of WeChat Search results for search terms: Official Account articles and Channels videos mixed, each saying in type whether it is an article or a video; by relevance, newest or hottest, filtered by time posted, or articles only or videos only: title or description, the source account's name, time published, an article's link (with a band of reads on some), a video's likes and saves | $0.02 per call |
|
|
105
|
+
| `dataxapi_wechat_channels_videos_search` | `DataXAPIWeChatChannelsVideoSearch` | Get a page of WeChat Channels videos for search terms through WeChat Search, by relevance, newest or hottest, filtered by time posted: description, the account's name and avatar, time published, likes and saves, length, cover | $0.02 per call |
|
|
106
|
+
| `dataxapi_xiaohongshu_notes_comments_list` | `DataXAPIXiaohongshuNoteComments` | Get a page of top-level comments on a Xiaohongshu note by ID or link, newest first or hottest first: text, commenter, likes, reply count, time posted | $0.02 per call |
|
|
107
|
+
| `dataxapi_tiktok_videos_search` | `DataXAPITikTokVideoSearch` | Search TikTok videos by keyword, 30 a page; sort by relevance, likes or time posted, and limit how recently they were posted | $0.002 per call |
|
|
108
|
+
| `dataxapi_youtube_videos_transcript_get` | `DataXAPIYouTubeTranscript` | Get the transcript of a YouTube video by ID or link: the whole text and timed segments | $0.002 per call |
|
|
109
|
+
<!-- tools:end -->
|
|
110
|
+
|
|
111
|
+
Live prices are on each endpoint's page at [dataxapi.com/apis](https://dataxapi.com/apis/?ref=langchain).
|
|
112
|
+
|
|
113
|
+
### Find and call any endpoint
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from langchain_dataxapi import DataXAPICall, DataXAPIFind
|
|
117
|
+
|
|
118
|
+
DataXAPIFind().invoke({"query": "bilibili user profile"})
|
|
119
|
+
# {"matches": [{"endpoint": "bilibili.users.get", "price_usd": "0.002", "example_params": {...}, ...}], ...}
|
|
120
|
+
|
|
121
|
+
DataXAPICall().invoke({"endpoint": "bilibili.users.get", "params": {"id": "8047632"}})
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
`params` may be an object or a JSON string. Lists such as `keywords` are sent as a JSON body.
|
|
125
|
+
|
|
126
|
+
### Errors
|
|
127
|
+
|
|
128
|
+
An error comes back as the tool's answer, so an agent can read it and correct itself, for example:
|
|
129
|
+
|
|
130
|
+
```text
|
|
131
|
+
DataXAPI error invalid_params: A parameter is invalid. Nothing was charged. Fix the request before trying again. Request ID: ….
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
It names the error code, whether anything was charged and whether to retry. Pass `handle_tool_error=False` to raise `ToolException` instead. Error codes: [dataxapi.com/docs](https://dataxapi.com/docs/?ref=langchain).
|
|
135
|
+
|
|
136
|
+
### Async
|
|
137
|
+
|
|
138
|
+
Every tool supports `ainvoke`:
|
|
139
|
+
|
|
140
|
+
```python
|
|
141
|
+
await DataXAPIDouyinVideoSearch().ainvoke({"query": "露营"})
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Development
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
uv sync --all-groups
|
|
148
|
+
make test # unit tests, HTTP mocked, network off; includes langchain-tests' ToolsUnitTests
|
|
149
|
+
make integration_test # live and free: dataxapi_find only. Paid tests need DATAXAPI_API_KEY and DATAXAPI_RUN_PAID=1
|
|
150
|
+
make generate # rewrite the endpoint tools and the tables from the live catalog
|
|
151
|
+
make lint
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
The endpoint tools in `langchain_dataxapi/endpoint_tools.py` are written by `scripts/generate_tools.py` from the free catalog at <https://api.dataxapi.com/v1/catalog>: names, argument schemas, allowed values and prices. Do not edit that file by hand.
|
|
155
|
+
|
|
156
|
+
## 中文说明
|
|
157
|
+
|
|
158
|
+
`langchain-dataxapi` 让 LangChain、LangGraph 智能体直接取抖音、小红书、微信公众号、视频号、微信搜一搜、微博、B 站、知乎、快手、巨量算数,以及 TikTok、YouTube、X、Reddit 的公开数据。
|
|
159
|
+
|
|
160
|
+
- 一个 Key 调全部 237 个接口:12 个常用接口各有现成工具,另有免费的“找接口”(`dataxapi_find`)和“调用任意接口”(`dataxapi_call`)。
|
|
161
|
+
- 不用登录你自己的平台账号,不要 Cookie、不扫码。
|
|
162
|
+
- 按次计费,出错不收费;每个工具的说明写了价格,每次返回都带这次花了多少(`billing.amount`,美元)。
|
|
163
|
+
- 免费试用最多 333 次,不用绑卡;最低充 $10,余额不过期。
|
|
164
|
+
|
|
165
|
+
安装与设置:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
pip install -U langchain-dataxapi
|
|
169
|
+
export DATAXAPI_API_KEY="dx_..." # 在 https://dataxapi.com/console/keys/ 创建
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
```python
|
|
173
|
+
from langchain.agents import create_agent
|
|
174
|
+
from langchain_dataxapi import DataXAPIToolkit
|
|
175
|
+
|
|
176
|
+
agent = create_agent(model="claude-sonnet-4-6", tools=DataXAPIToolkit().get_tools())
|
|
177
|
+
question = "这周小红书上关于露营咖啡的笔记里,点赞最多的三篇讲了什么?评论区怎么说?"
|
|
178
|
+
agent.invoke({"messages": [{"role": "user", "content": question}]})
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
<!-- tools-zh:start -->
|
|
182
|
+
| 工具 | 类名 | 拿到什么 | 价格 |
|
|
183
|
+
|---|---|---|---|
|
|
184
|
+
| `dataxapi_find` | `DataXAPIFind` | 用一句话描述要的数据,列出能用的接口、价格和参数 | 免费 |
|
|
185
|
+
| `dataxapi_call` | `DataXAPICall` | 用接口编号加参数调用全部接口里的任何一个 | 按该接口的价格 |
|
|
186
|
+
| `dataxapi_xiaohongshu_notes_search` | `DataXAPIXiaohongshuNoteSearch` | 小红书笔记搜索 | $0.02 一次,出错不收费 |
|
|
187
|
+
| `dataxapi_douyin_videos_search` | `DataXAPIDouyinVideoSearch` | 抖音视频搜索 | $0.02 一次,出错不收费 |
|
|
188
|
+
| `dataxapi_wechat_mp_accounts_articles_list` | `DataXAPIWeChatOfficialAccountArticles` | 微信公众号文章列表 | $0.02 一次,出错不收费 |
|
|
189
|
+
| `dataxapi_douyin_videos_comments_list` | `DataXAPIDouyinVideoComments` | 抖音视频评论 | $0.002 一次,出错不收费 |
|
|
190
|
+
| `dataxapi_douyin_videos_metrics` | `DataXAPIDouyinVideoMetrics` | 抖音视频播放量 | $0.002 一次,出错不收费 |
|
|
191
|
+
| `dataxapi_wechat_mp_articles_get` | `DataXAPIWeChatArticle` | 微信公众号文章详情 | $0.02 一次,出错不收费 |
|
|
192
|
+
| `dataxapi_douyin_index_keywords_history` | `DataXAPIDouyinKeywordTrend` | 抖音巨量算数关键词热度趋势 | $0.006 一次,出错不收费 |
|
|
193
|
+
| `dataxapi_wechat_posts_search` | `DataXAPIWeChatSearch` | 微信搜一搜综合搜索 | $0.02 一次,出错不收费 |
|
|
194
|
+
| `dataxapi_wechat_channels_videos_search` | `DataXAPIWeChatChannelsVideoSearch` | 微信搜一搜视频号视频搜索 | $0.02 一次,出错不收费 |
|
|
195
|
+
| `dataxapi_xiaohongshu_notes_comments_list` | `DataXAPIXiaohongshuNoteComments` | 小红书笔记评论 | $0.02 一次,出错不收费 |
|
|
196
|
+
| `dataxapi_tiktok_videos_search` | `DataXAPITikTokVideoSearch` | TikTok 视频搜索 | $0.002 一次,出错不收费 |
|
|
197
|
+
| `dataxapi_youtube_videos_transcript_get` | `DataXAPIYouTubeTranscript` | YouTube 视频字幕 | $0.002 一次,出错不收费 |
|
|
198
|
+
<!-- tools-zh:end -->
|
|
199
|
+
|
|
200
|
+
翻页:把上一次返回的 `page.next_cursor` 作为 `cursor` 再调一次,每页单独计费。出错时工具返回一段文字,写明错误码、有没有收费、要不要重试,智能体可以据此自己改正。
|
|
201
|
+
|
|
202
|
+
## Links
|
|
203
|
+
|
|
204
|
+
- Endpoints and prices: <https://dataxapi.com/apis/?ref=langchain>
|
|
205
|
+
- API docs: <https://dataxapi.com/docs/?ref=langchain>
|
|
206
|
+
- Catalog for AI tools: <https://dataxapi.com/llms-full.txt>
|
|
207
|
+
- Support: support@dataxapi.com
|
|
208
|
+
|
|
209
|
+
## License
|
|
210
|
+
|
|
211
|
+
MIT
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""LangChain tools for DataXAPI: social media and market data for agents.
|
|
2
|
+
|
|
3
|
+
``DataXAPIFind`` finds the endpoint for a need (free), ``DataXAPICall`` calls any endpoint by ID, and
|
|
4
|
+
one tool per popular endpoint calls it with typed arguments. ``DataXAPIToolkit`` gives them all.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from importlib import metadata
|
|
8
|
+
|
|
9
|
+
from langchain_dataxapi._client import DataXAPIClient, DataXAPIError
|
|
10
|
+
from langchain_dataxapi.endpoint_tools import (
|
|
11
|
+
ENDPOINT_TOOLS,
|
|
12
|
+
DataXAPIDouyinKeywordTrend,
|
|
13
|
+
DataXAPIDouyinVideoComments,
|
|
14
|
+
DataXAPIDouyinVideoMetrics,
|
|
15
|
+
DataXAPIDouyinVideoSearch,
|
|
16
|
+
DataXAPITikTokVideoSearch,
|
|
17
|
+
DataXAPIWeChatArticle,
|
|
18
|
+
DataXAPIWeChatChannelsVideoSearch,
|
|
19
|
+
DataXAPIWeChatOfficialAccountArticles,
|
|
20
|
+
DataXAPIWeChatSearch,
|
|
21
|
+
DataXAPIXiaohongshuNoteComments,
|
|
22
|
+
DataXAPIXiaohongshuNoteSearch,
|
|
23
|
+
DataXAPIYouTubeTranscript,
|
|
24
|
+
)
|
|
25
|
+
from langchain_dataxapi.toolkits import DataXAPIToolkit
|
|
26
|
+
from langchain_dataxapi.tools import DataXAPIBaseTool, DataXAPICall, DataXAPIEndpointTool, DataXAPIFind
|
|
27
|
+
|
|
28
|
+
try:
|
|
29
|
+
__version__ = metadata.version("langchain-dataxapi")
|
|
30
|
+
except metadata.PackageNotFoundError:
|
|
31
|
+
__version__ = ""
|
|
32
|
+
|
|
33
|
+
__all__ = [
|
|
34
|
+
"ENDPOINT_TOOLS",
|
|
35
|
+
"DataXAPIBaseTool",
|
|
36
|
+
"DataXAPICall",
|
|
37
|
+
"DataXAPIClient",
|
|
38
|
+
"DataXAPIDouyinKeywordTrend",
|
|
39
|
+
"DataXAPIDouyinVideoComments",
|
|
40
|
+
"DataXAPIDouyinVideoMetrics",
|
|
41
|
+
"DataXAPIDouyinVideoSearch",
|
|
42
|
+
"DataXAPIEndpointTool",
|
|
43
|
+
"DataXAPIError",
|
|
44
|
+
"DataXAPIFind",
|
|
45
|
+
"DataXAPITikTokVideoSearch",
|
|
46
|
+
"DataXAPIToolkit",
|
|
47
|
+
"DataXAPIWeChatArticle",
|
|
48
|
+
"DataXAPIWeChatChannelsVideoSearch",
|
|
49
|
+
"DataXAPIWeChatOfficialAccountArticles",
|
|
50
|
+
"DataXAPIWeChatSearch",
|
|
51
|
+
"DataXAPIXiaohongshuNoteComments",
|
|
52
|
+
"DataXAPIXiaohongshuNoteSearch",
|
|
53
|
+
"DataXAPIYouTubeTranscript",
|
|
54
|
+
"__version__",
|
|
55
|
+
]
|