langchain-thordata 0.2.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.
@@ -0,0 +1,13 @@
1
+ .venv/
2
+ .venv-*/
3
+ __pycache__/
4
+ *.py[cod]
5
+ *.egg-info/
6
+ .pytest_cache/
7
+ .ruff_cache/
8
+ .mypy_cache/
9
+ build/
10
+ dist/
11
+ .idea/
12
+ .coverage
13
+ htmlcov/
@@ -0,0 +1,21 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ - Switch the default API endpoint from `/fast_request` to `/request`.
6
+ - Support every SERP engine and form parameter handled by `/request`.
7
+ - Keep `google_search` and `google_places` as compatibility aliases.
8
+ - Allow specialized engines that do not use a `q` parameter.
9
+ - Treat `/request` responses with `code=0` as API failures.
10
+ - Reuse synchronous and asynchronous HTTP connection pools per client instance.
11
+ - Keep the public client JSON-focused because the current `/request` endpoint does not guarantee HTML.
12
+ - Normalize convenience parameter aliases consistently with the JavaScript SDK.
13
+ - Add a dedicated `ThorDataNotCollectedError` for business code `300`.
14
+ - Normalize JSON-string response envelopes before LangChain serialization.
15
+
16
+ ## 0.1.0
17
+
18
+ - Add synchronous and asynchronous ThorData SERP clients.
19
+ - Add the `ThorDataSearchTool` LangChain tool.
20
+ - Restrict V1 to supported SERP engines and exclude Web Scraper access.
21
+ - Add unit tests, examples, type information, and CI configuration.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ThorData SDK Contributors
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,198 @@
1
+ Metadata-Version: 2.5
2
+ Name: langchain-thordata
3
+ Version: 0.2.0
4
+ Summary: LangChain tools and Python client for the ThorData SERP API
5
+ Project-URL: Homepage, https://www.thordata.com/
6
+ Project-URL: Documentation, https://doc.thordata.com/
7
+ Author: ThorData
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Keywords: ai-agents,langchain,search,serp,thordata
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Typing :: Typed
19
+ Requires-Python: >=3.10
20
+ Requires-Dist: httpx<1.0,>=0.27
21
+ Requires-Dist: langchain-core<2.0,>=0.3
22
+ Requires-Dist: pydantic<3.0,>=2.7
23
+ Provides-Extra: test
24
+ Requires-Dist: build<2,>=1.2; extra == 'test'
25
+ Requires-Dist: pytest-asyncio<2,>=0.24; extra == 'test'
26
+ Requires-Dist: pytest<10,>=8; extra == 'test'
27
+ Requires-Dist: ruff<1,>=0.9; extra == 'test'
28
+ Description-Content-Type: text/markdown
29
+
30
+ # LangChain Thordata for Python
31
+
32
+ Connect [Thordata](https://www.thordata.com/serp-api/mcp?utm_source=MCP&utm_term=mcp)
33
+ SERP to Python applications and LangChain agents for real-time search.
34
+
35
+ This package exposes Thordata search capabilities through a Python client and a
36
+ LangChain search tool. Version 1 targets Thordata's synchronous SERP endpoint,
37
+ exposes search-result APIs only, and does not expose Web Scraper APIs or the
38
+ `google_webpage` engine.
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ pip install langchain-thordata
44
+ ```
45
+
46
+ For local development:
47
+
48
+ ```bash
49
+ python -m pip install -e ".[test]"
50
+ ```
51
+
52
+ ## Configuration
53
+
54
+ Set a ThorData SERP API key:
55
+
56
+ ```bash
57
+ export THORDATA_API_KEY="your-api-key"
58
+ ```
59
+
60
+ `THORDATA_API_TOKEN` is accepted as a compatibility alias. The default API URL
61
+ is `https://scraperapi.thordata.com/request`; override it for development
62
+ with `THORDATA_SERP_API_URL`.
63
+
64
+ ## Python client
65
+
66
+ ```python
67
+ from langchain_thordata import ThorDataClient
68
+
69
+ with ThorDataClient() as client:
70
+ results = client.search(
71
+ q="latest AI agent research",
72
+ engine="google_search",
73
+ gl="us",
74
+ hl="en",
75
+ num=10,
76
+ )
77
+ print(results)
78
+ ```
79
+
80
+ The client reuses its HTTP connection pool until `close()` or `aclose()` is
81
+ called. Prefer a synchronous or asynchronous context manager. It also provides
82
+ `await client.asearch(...)` for asynchronous callers. The current `/request`
83
+ endpoint does not guarantee HTML, so the client intentionally exposes JSON
84
+ search methods only.
85
+
86
+ The client accepts every form parameter supported by `/request`. Pass
87
+ API-native parameters either as keyword arguments or in the first mapping
88
+ argument:
89
+
90
+ ```python
91
+ flights = client.search(
92
+ {
93
+ "departure_id": "SFO",
94
+ "arrival_id": "JFK",
95
+ "outbound_date": "2026-10-01",
96
+ "return_date": "2026-10-08",
97
+ },
98
+ engine="google_flights",
99
+ )
100
+ ```
101
+
102
+ In either form, the convenience names `query`, `country`, and `language` map to
103
+ `q`, `gl`, and `hl`. Explicit API-native names such as `q`, `gl`, `hl`, and
104
+ `text` are preserved. For Yandex, `query` or `q` is sent as `text`.
105
+
106
+ ## LangChain tool
107
+
108
+ ```python
109
+ from langchain_thordata import ThorDataSearchTool
110
+
111
+ tool = ThorDataSearchTool()
112
+ result = tool.invoke(
113
+ {
114
+ "query": "latest AI agent research",
115
+ "engine": "google_news",
116
+ "country": "us",
117
+ "language": "en",
118
+ "num": 5,
119
+ }
120
+ )
121
+ print(result)
122
+ ```
123
+
124
+ Specialized parameters are available to the tool through `params`:
125
+
126
+ ```python
127
+ result = tool.invoke(
128
+ {
129
+ "engine": "google_scholar_author",
130
+ "params": {"author_id": "EicYvbwAAAAJ", "sort": "pubdate"},
131
+ }
132
+ )
133
+ ```
134
+
135
+ The tool can be passed directly to a LangChain agent:
136
+
137
+ ```python
138
+ from langchain.agents import create_agent
139
+ from langchain_thordata import ThorDataSearchTool
140
+
141
+ agent = create_agent(model, tools=[ThorDataSearchTool()])
142
+ ```
143
+
144
+ The agent example requires the separate `langchain` package; the integration's
145
+ runtime dependency stays limited to `langchain-core`.
146
+
147
+ ## Supported engines
148
+
149
+ - Google search: `google`, `google_light`, `google_web`, `google_images`,
150
+ `google_videos`, `google_news`, `google_shopping`, `google_local`,
151
+ `google_product`, `google_lens`, `google_trends`, `google_maps`,
152
+ `google_hotels`, `google_jobs`, and `google_ai_mode`.
153
+ - Google verticals: `google_scholar`, `google_scholar_cite`,
154
+ `google_scholar_author`, `google_play`, `google_play_product`,
155
+ `google_play_games`, `google_play_movies`, `google_play_books`,
156
+ `google_finance`, `google_finance_markets`, `google_flights`,
157
+ `google_patents`, and `google_patents_details`.
158
+ - Bing: `bing`, `bing_images`, `bing_videos`, `bing_news`, `bing_shopping`,
159
+ and `bing_maps`.
160
+ - Other providers: `yandex` and `duckduckgo`. For Yandex, the LangChain
161
+ `query` field is sent as the API's required `text` parameter.
162
+
163
+ For compatibility, `google_search` maps to `google`, and `google_places` maps
164
+ to `google_local` before the request is sent.
165
+
166
+ Unsupported parameters are omitted from the request. Unsupported engines are
167
+ rejected because silently switching a search source would change user intent.
168
+
169
+ Every request sends fixed integration metadata:
170
+
171
+ - Platform: `langchain`
172
+ - Source: `python-sdk`
173
+
174
+ These values are sent as both request headers and form metadata. The current
175
+ ThorData service records the form metadata without forwarding it to the search
176
+ provider.
177
+
178
+ The API key is never included in tool output or exception messages. Business
179
+ code `300` raises `ThorDataNotCollectedError`; all API exceptions retain their
180
+ numeric `code` for programmatic handling.
181
+
182
+ JSON-string response envelopes are normalized by the client before the
183
+ LangChain tool serializes its result, so callers parse the tool output once.
184
+
185
+ ## Development
186
+
187
+ ```bash
188
+ ruff check .
189
+ pytest
190
+ python -m build
191
+ ```
192
+
193
+ Live integration tests should use a dedicated test account and API key. Unit
194
+ tests use an in-memory HTTP transport and do not call Thordata services.
195
+
196
+ ## Learn more
197
+
198
+ - [Thordata SERP API](https://www.thordata.com/serp-api/mcp?utm_source=MCP&utm_term=mcp)
@@ -0,0 +1,169 @@
1
+ # LangChain Thordata for Python
2
+
3
+ Connect [Thordata](https://www.thordata.com/serp-api/mcp?utm_source=MCP&utm_term=mcp)
4
+ SERP to Python applications and LangChain agents for real-time search.
5
+
6
+ This package exposes Thordata search capabilities through a Python client and a
7
+ LangChain search tool. Version 1 targets Thordata's synchronous SERP endpoint,
8
+ exposes search-result APIs only, and does not expose Web Scraper APIs or the
9
+ `google_webpage` engine.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pip install langchain-thordata
15
+ ```
16
+
17
+ For local development:
18
+
19
+ ```bash
20
+ python -m pip install -e ".[test]"
21
+ ```
22
+
23
+ ## Configuration
24
+
25
+ Set a ThorData SERP API key:
26
+
27
+ ```bash
28
+ export THORDATA_API_KEY="your-api-key"
29
+ ```
30
+
31
+ `THORDATA_API_TOKEN` is accepted as a compatibility alias. The default API URL
32
+ is `https://scraperapi.thordata.com/request`; override it for development
33
+ with `THORDATA_SERP_API_URL`.
34
+
35
+ ## Python client
36
+
37
+ ```python
38
+ from langchain_thordata import ThorDataClient
39
+
40
+ with ThorDataClient() as client:
41
+ results = client.search(
42
+ q="latest AI agent research",
43
+ engine="google_search",
44
+ gl="us",
45
+ hl="en",
46
+ num=10,
47
+ )
48
+ print(results)
49
+ ```
50
+
51
+ The client reuses its HTTP connection pool until `close()` or `aclose()` is
52
+ called. Prefer a synchronous or asynchronous context manager. It also provides
53
+ `await client.asearch(...)` for asynchronous callers. The current `/request`
54
+ endpoint does not guarantee HTML, so the client intentionally exposes JSON
55
+ search methods only.
56
+
57
+ The client accepts every form parameter supported by `/request`. Pass
58
+ API-native parameters either as keyword arguments or in the first mapping
59
+ argument:
60
+
61
+ ```python
62
+ flights = client.search(
63
+ {
64
+ "departure_id": "SFO",
65
+ "arrival_id": "JFK",
66
+ "outbound_date": "2026-10-01",
67
+ "return_date": "2026-10-08",
68
+ },
69
+ engine="google_flights",
70
+ )
71
+ ```
72
+
73
+ In either form, the convenience names `query`, `country`, and `language` map to
74
+ `q`, `gl`, and `hl`. Explicit API-native names such as `q`, `gl`, `hl`, and
75
+ `text` are preserved. For Yandex, `query` or `q` is sent as `text`.
76
+
77
+ ## LangChain tool
78
+
79
+ ```python
80
+ from langchain_thordata import ThorDataSearchTool
81
+
82
+ tool = ThorDataSearchTool()
83
+ result = tool.invoke(
84
+ {
85
+ "query": "latest AI agent research",
86
+ "engine": "google_news",
87
+ "country": "us",
88
+ "language": "en",
89
+ "num": 5,
90
+ }
91
+ )
92
+ print(result)
93
+ ```
94
+
95
+ Specialized parameters are available to the tool through `params`:
96
+
97
+ ```python
98
+ result = tool.invoke(
99
+ {
100
+ "engine": "google_scholar_author",
101
+ "params": {"author_id": "EicYvbwAAAAJ", "sort": "pubdate"},
102
+ }
103
+ )
104
+ ```
105
+
106
+ The tool can be passed directly to a LangChain agent:
107
+
108
+ ```python
109
+ from langchain.agents import create_agent
110
+ from langchain_thordata import ThorDataSearchTool
111
+
112
+ agent = create_agent(model, tools=[ThorDataSearchTool()])
113
+ ```
114
+
115
+ The agent example requires the separate `langchain` package; the integration's
116
+ runtime dependency stays limited to `langchain-core`.
117
+
118
+ ## Supported engines
119
+
120
+ - Google search: `google`, `google_light`, `google_web`, `google_images`,
121
+ `google_videos`, `google_news`, `google_shopping`, `google_local`,
122
+ `google_product`, `google_lens`, `google_trends`, `google_maps`,
123
+ `google_hotels`, `google_jobs`, and `google_ai_mode`.
124
+ - Google verticals: `google_scholar`, `google_scholar_cite`,
125
+ `google_scholar_author`, `google_play`, `google_play_product`,
126
+ `google_play_games`, `google_play_movies`, `google_play_books`,
127
+ `google_finance`, `google_finance_markets`, `google_flights`,
128
+ `google_patents`, and `google_patents_details`.
129
+ - Bing: `bing`, `bing_images`, `bing_videos`, `bing_news`, `bing_shopping`,
130
+ and `bing_maps`.
131
+ - Other providers: `yandex` and `duckduckgo`. For Yandex, the LangChain
132
+ `query` field is sent as the API's required `text` parameter.
133
+
134
+ For compatibility, `google_search` maps to `google`, and `google_places` maps
135
+ to `google_local` before the request is sent.
136
+
137
+ Unsupported parameters are omitted from the request. Unsupported engines are
138
+ rejected because silently switching a search source would change user intent.
139
+
140
+ Every request sends fixed integration metadata:
141
+
142
+ - Platform: `langchain`
143
+ - Source: `python-sdk`
144
+
145
+ These values are sent as both request headers and form metadata. The current
146
+ ThorData service records the form metadata without forwarding it to the search
147
+ provider.
148
+
149
+ The API key is never included in tool output or exception messages. Business
150
+ code `300` raises `ThorDataNotCollectedError`; all API exceptions retain their
151
+ numeric `code` for programmatic handling.
152
+
153
+ JSON-string response envelopes are normalized by the client before the
154
+ LangChain tool serializes its result, so callers parse the tool output once.
155
+
156
+ ## Development
157
+
158
+ ```bash
159
+ ruff check .
160
+ pytest
161
+ python -m build
162
+ ```
163
+
164
+ Live integration tests should use a dedicated test account and API key. Unit
165
+ tests use an in-memory HTTP transport and do not call Thordata services.
166
+
167
+ ## Learn more
168
+
169
+ - [Thordata SERP API](https://www.thordata.com/serp-api/mcp?utm_source=MCP&utm_term=mcp)
@@ -0,0 +1,13 @@
1
+ """Run a ThorData search without creating an agent."""
2
+
3
+ from langchain_thordata import ThorDataClient
4
+
5
+ with ThorDataClient() as client:
6
+ result = client.search(
7
+ q="latest AI agent research",
8
+ engine="google_search",
9
+ gl="us",
10
+ hl="en",
11
+ num=5,
12
+ )
13
+ print(result)
@@ -0,0 +1,15 @@
1
+ """Invoke the ThorData LangChain tool directly."""
2
+
3
+ from langchain_thordata import ThorDataSearchTool
4
+
5
+ tool = ThorDataSearchTool()
6
+ result = tool.invoke(
7
+ {
8
+ "query": "latest AI agent research",
9
+ "engine": "google_news",
10
+ "country": "us",
11
+ "language": "en",
12
+ "num": 5,
13
+ }
14
+ )
15
+ print(result)
@@ -0,0 +1,36 @@
1
+ """LangChain integration for the ThorData SERP API."""
2
+
3
+ from ._version import __version__
4
+ from .client import SUPPORTED_ENGINES, SearchResponse, ThorDataClient
5
+ from .exceptions import (
6
+ ThorDataAPIError,
7
+ ThorDataAuthenticationError,
8
+ ThorDataConfigurationError,
9
+ ThorDataConnectionError,
10
+ ThorDataError,
11
+ ThorDataInvalidRequestError,
12
+ ThorDataNotCollectedError,
13
+ ThorDataPermissionError,
14
+ ThorDataRateLimitError,
15
+ ThorDataTimeoutError,
16
+ )
17
+ from .tools import ThorDataSearchInput, ThorDataSearchTool
18
+
19
+ __all__ = [
20
+ "SUPPORTED_ENGINES",
21
+ "SearchResponse",
22
+ "ThorDataAPIError",
23
+ "ThorDataAuthenticationError",
24
+ "ThorDataClient",
25
+ "ThorDataConfigurationError",
26
+ "ThorDataConnectionError",
27
+ "ThorDataError",
28
+ "ThorDataInvalidRequestError",
29
+ "ThorDataNotCollectedError",
30
+ "ThorDataPermissionError",
31
+ "ThorDataRateLimitError",
32
+ "ThorDataSearchInput",
33
+ "ThorDataSearchTool",
34
+ "ThorDataTimeoutError",
35
+ "__version__",
36
+ ]
@@ -0,0 +1 @@
1
+ __version__ = "0.2.0"