serpapi-search-tools 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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 SerpApi
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,466 @@
1
+ Metadata-Version: 2.4
2
+ Name: serpapi-search-tools
3
+ Version: 0.1.0
4
+ Summary: Add live SerpApi search to Python agents and agent SDKs.
5
+ Keywords: agents,ai,search,serpapi,tools
6
+ Author: SerpApi
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Classifier: Development Status :: 3 - Alpha
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3 :: Only
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Typing :: Typed
19
+ Requires-Dist: serpapi>=1.0.0,<2
20
+ Requires-Dist: agno>=2.6.19,<3 ; extra == 'agno'
21
+ Requires-Dist: openai>=1.0.0,<3 ; extra == 'agno'
22
+ Requires-Dist: autogen-agentchat>=0.7.5,<0.8 ; extra == 'autogen'
23
+ Requires-Dist: autogen-core>=0.7.5,<0.8 ; extra == 'autogen'
24
+ Requires-Dist: autogen-ext[openai]>=0.7.5,<0.8 ; extra == 'autogen'
25
+ Requires-Dist: claude-agent-sdk>=0.2.108,<1 ; extra == 'claude-agent-sdk'
26
+ Requires-Dist: crewai>=1.6.1,<2 ; python_full_version < '3.14' and extra == 'crewai'
27
+ Requires-Dist: agno>=2.6.19,<3 ; extra == 'frameworks'
28
+ Requires-Dist: autogen-core>=0.7.5,<0.8 ; extra == 'frameworks'
29
+ Requires-Dist: autogen-agentchat>=0.7.5,<0.8 ; extra == 'frameworks'
30
+ Requires-Dist: autogen-ext[openai]>=0.7.5,<0.8 ; extra == 'frameworks'
31
+ Requires-Dist: claude-agent-sdk>=0.2.108,<1 ; extra == 'frameworks'
32
+ Requires-Dist: crewai>=1.6.1,<2 ; python_full_version < '3.14' and extra == 'frameworks'
33
+ Requires-Dist: haystack-ai>=2.30.2,<4 ; extra == 'frameworks'
34
+ Requires-Dist: langchain>=1.3.11,<2 ; extra == 'frameworks'
35
+ Requires-Dist: langchain-core>=1.4.8,<2 ; extra == 'frameworks'
36
+ Requires-Dist: langgraph>=1.2.6,<2 ; extra == 'frameworks'
37
+ Requires-Dist: llama-index-core>=0.14.22,<0.15 ; extra == 'frameworks'
38
+ Requires-Dist: openai>=1.0.0,<3 ; extra == 'frameworks'
39
+ Requires-Dist: pydantic-ai>=1.30.1,<3 ; extra == 'frameworks'
40
+ Requires-Dist: semantic-kernel>=1.36.0,<2 ; extra == 'frameworks'
41
+ Requires-Dist: smolagents>=1.26.0,<2 ; extra == 'frameworks'
42
+ Requires-Dist: google-adk>=2.3.0,<3 ; extra == 'google-adk'
43
+ Requires-Dist: haystack-ai>=2.30.2,<4 ; extra == 'haystack'
44
+ Requires-Dist: langchain>=1.3.11,<2 ; extra == 'langchain'
45
+ Requires-Dist: langchain-core>=1.4.8,<2 ; extra == 'langchain'
46
+ Requires-Dist: langchain>=1.3.11,<2 ; extra == 'langgraph'
47
+ Requires-Dist: langchain-core>=1.4.8,<2 ; extra == 'langgraph'
48
+ Requires-Dist: langgraph>=1.2.6,<2 ; extra == 'langgraph'
49
+ Requires-Dist: llama-index-core>=0.14.22,<0.15 ; extra == 'llamaindex'
50
+ Requires-Dist: agent-framework-openai>=1.10.1,<2 ; extra == 'microsoft-agent-framework'
51
+ Requires-Dist: openai-agents>=0.18.3,<1 ; extra == 'openai-agents'
52
+ Requires-Dist: pydantic-ai>=1.30.1,<3 ; extra == 'pydantic-ai'
53
+ Requires-Dist: openai>=1.0.0,<3 ; extra == 'semantic-kernel'
54
+ Requires-Dist: semantic-kernel>=1.36.0,<2 ; extra == 'semantic-kernel'
55
+ Requires-Dist: openai>=1.0.0,<3 ; extra == 'smolagents'
56
+ Requires-Dist: smolagents>=1.26.0,<2 ; extra == 'smolagents'
57
+ Requires-Python: >=3.10
58
+ Project-URL: Documentation, https://serpapi.github.io/serpapi-search-tools-python/
59
+ Project-URL: Repository, https://github.com/serpapi/serpapi-search-tools-python
60
+ Project-URL: Issues, https://github.com/serpapi/serpapi-search-tools-python/issues
61
+ Provides-Extra: agno
62
+ Provides-Extra: autogen
63
+ Provides-Extra: claude-agent-sdk
64
+ Provides-Extra: crewai
65
+ Provides-Extra: frameworks
66
+ Provides-Extra: google-adk
67
+ Provides-Extra: haystack
68
+ Provides-Extra: langchain
69
+ Provides-Extra: langgraph
70
+ Provides-Extra: llamaindex
71
+ Provides-Extra: microsoft-agent-framework
72
+ Provides-Extra: openai-agents
73
+ Provides-Extra: pydantic-ai
74
+ Provides-Extra: semantic-kernel
75
+ Provides-Extra: smolagents
76
+ Description-Content-Type: text/markdown
77
+
78
+ # serpapi-search-tools
79
+
80
+ [![PyPI version](https://img.shields.io/pypi/v/serpapi-search-tools.svg)](https://pypi.org/project/serpapi-search-tools/)
81
+ [![CI](https://github.com/serpapi/serpapi-search-tools-python/actions/workflows/ci.yml/badge.svg)](https://github.com/serpapi/serpapi-search-tools-python/actions/workflows/ci.yml)
82
+ [![Python versions](https://img.shields.io/pypi/pyversions/serpapi-search-tools.svg)](https://pypi.org/project/serpapi-search-tools/)
83
+ [![License: MIT](https://img.shields.io/pypi/l/serpapi-search-tools.svg)](https://github.com/serpapi/serpapi-search-tools-python/blob/main/LICENSE)
84
+
85
+ [Read the full documentation](https://serpapi.github.io/serpapi-search-tools-python/)
86
+ for guides, SDK examples, recipes, and the API reference.
87
+
88
+ Give Python agents live web, news, maps, image, shopping, video, hotel, and
89
+ flight search through small typed tools.
90
+
91
+ `serpapi-search-tools` connects [SerpApi](https://serpapi.com) to popular Python
92
+ agent SDKs. It provides a separate constructor for each kind of search, so you
93
+ can give an agent only the capabilities it needs:
94
+
95
+ ```python
96
+ from serpapi_search_tools import maps_search, news_search, web_search
97
+
98
+ tools = [
99
+ web_search(),
100
+ news_search(),
101
+ maps_search(),
102
+ ]
103
+ ```
104
+
105
+ When one supported agent SDK is installed, the package detects it and creates
106
+ tools ready for that SDK. Each search tool asks for the information it needs:
107
+ web search uses a query, hotel search requires stay dates, and flight search
108
+ uses airports and travel dates. Inputs are validated before a request is sent
109
+ to SerpApi, helping prevent failed searches and unnecessary API usage.
110
+
111
+ ## Supported agent SDKs
112
+
113
+ | SDK | Install extra / provider | Returned tool |
114
+ | --- | --- | --- |
115
+ | OpenAI Agents SDK | `openai-agents` | OpenAI Agents `FunctionTool` |
116
+ | Pydantic AI | `pydantic-ai` | Pydantic AI `Tool` |
117
+ | LangChain | `langchain` | LangChain `StructuredTool` |
118
+ | LangGraph | `langgraph` | LangChain-compatible structured tool |
119
+ | CrewAI | `crewai` | CrewAI `BaseTool` |
120
+ | LlamaIndex | `llamaindex` | LlamaIndex `FunctionTool` |
121
+ | Claude Agent SDK | `claude-agent-sdk` | Claude SDK MCP tool |
122
+ | Microsoft Agent Framework | `microsoft-agent-framework` | Microsoft Agent Framework `FunctionTool` |
123
+ | AutoGen | `autogen` | AutoGen `FunctionTool` |
124
+ | Haystack | `haystack` | Haystack `Tool` |
125
+ | Semantic Kernel | `semantic-kernel` | Semantic Kernel function |
126
+ | Agno | `agno` | Agno `Function` |
127
+ | smolagents | `smolagents` | smolagents `Tool` |
128
+ | Google ADK | `google-adk` | Google ADK `FunctionTool` |
129
+
130
+
131
+ ## Install
132
+
133
+ If your agent SDK is already installed, add only the base package:
134
+
135
+ ```bash
136
+ pip install serpapi-search-tools
137
+ ```
138
+
139
+ If you want this package to install a compatible agent SDK too, choose its
140
+ extra. For example:
141
+
142
+ ```bash
143
+ pip install "serpapi-search-tools[openai-agents]"
144
+ ```
145
+
146
+ Extras are available for all supported SDKs listed above.
147
+
148
+ Set a SerpApi key:
149
+
150
+ ```bash
151
+ export SERPAPI_API_KEY="your-key"
152
+ ```
153
+
154
+ `SERPAPI_KEY` is also supported. A directly supplied `api_key=` takes
155
+ precedence over environment variables.
156
+
157
+ ## Quickstart: automatic SDK detection
158
+
159
+ This quickstart uses OpenAI Agents SDK to demonstrate automatic detection. It
160
+ assumes the SDK is already installed in your environment (install it with
161
+ `pip install openai-agents` if needed). Then add the base package:
162
+
163
+ ```bash
164
+ pip install serpapi-search-tools
165
+ ```
166
+
167
+ With one supported SDK installed, create the tool without any configuration.
168
+ The package detects OpenAI Agents SDK and returns its native `FunctionTool`.
169
+ This example also expects the `OPENAI_API_KEY` used by your agent.
170
+
171
+ ```python
172
+ from agents import Agent, Runner
173
+
174
+ from serpapi_search_tools import web_search
175
+
176
+ agent = Agent(
177
+ name="research-agent",
178
+ instructions="Use web search when the answer needs current information.",
179
+ tools=[web_search()],
180
+ )
181
+
182
+ result = Runner.run_sync(
183
+ agent,
184
+ "Find three recent Python packaging changes and explain why they matter.",
185
+ )
186
+ print(result.final_output)
187
+ ```
188
+
189
+ ## Quickstart: explicit LangChain provider
190
+
191
+ Install the LangChain extra and the model backend used by this example:
192
+
193
+ ```bash
194
+ pip install "serpapi-search-tools[langchain]" langchain-openai
195
+ ```
196
+
197
+ The `langchain` extra installs a compatible LangChain version.
198
+ `langchain-openai` provides this example's model integration; replace it with
199
+ the backend your LangChain application uses. With `langchain-openai`, set
200
+ `OPENAI_API_KEY` before running the agent.
201
+
202
+ ```python
203
+ from langchain.agents import create_agent
204
+ from langchain_openai import ChatOpenAI
205
+
206
+ from serpapi_search_tools import maps_search, news_search, web_search
207
+
208
+ agent = create_agent(
209
+ model=ChatOpenAI(model="gpt-5.4-mini", temperature=0),
210
+ tools=[
211
+ web_search(provider="langchain"),
212
+ news_search(provider="langchain"),
213
+ maps_search(provider="langchain"),
214
+ ],
215
+ )
216
+
217
+ result = agent.invoke(
218
+ {
219
+ "messages": [
220
+ {
221
+ "role": "user",
222
+ "content": (
223
+ "Research coffee culture in Austin using current reporting, "
224
+ "local places, and general web sources."
225
+ ),
226
+ }
227
+ ]
228
+ }
229
+ )
230
+ print(result["messages"][-1].content)
231
+ ```
232
+
233
+ When LangChain is the only supported SDK installed, these constructors are
234
+ also auto-detected, so `web_search()` is enough. Supplying
235
+ `provider="langchain"` explicitly is useful when several supported SDKs share
236
+ an environment or when you want the integration choice to be visible in code.
237
+
238
+ For a step-by-step explanation, keys, customization, and troubleshooting, read
239
+ the [detailed quickstart](https://serpapi.github.io/serpapi-search-tools-python/user-guide/quickstart.html).
240
+
241
+ Browse the [runnable examples](https://github.com/serpapi/serpapi-search-tools-python/tree/main/examples)
242
+ for focused integrations or the [agent cookbook](https://serpapi.github.io/serpapi-search-tools-python/docs/cookbook/)
243
+ for complete, task-oriented agents built with every supported SDK.
244
+
245
+ ## Choose the right tool
246
+
247
+ | Constructor | SerpApi engine(s) | Required search inputs |
248
+ | --- | --- | --- |
249
+ | `web_search` | `google`, `google_light`, `bing`, `yahoo`, `duckduckgo` | `query` |
250
+ | `news_search` | `google_news` | `query` |
251
+ | `maps_search` | `google_maps` | `query` |
252
+ | `images_search` | `google_images` | `query` |
253
+ | `shopping_search` | `google_shopping`, `amazon`, `walmart`, `ebay` | `query` |
254
+ | `videos_search` | `youtube` | `query` |
255
+ | `hotels_search` | `google_hotels` | `query`, `check_in_date`, `check_out_date` |
256
+ | `flights_search` | `google_flights` | `departure_id`, `arrival_id`, `outbound_date` |
257
+ | `travel_explore_search` | `google_travel_explore` | `departure_id` |
258
+
259
+ Only `web_search` and `shopping_search` expose an `engine` choice to the model.
260
+ Every other constructor fixes the engine and presents a schema tailored to that
261
+ search intent.
262
+
263
+ ### General web
264
+
265
+ ```python
266
+ from serpapi_search_tools import WebSearchEngine, web_search
267
+
268
+ tool = web_search(
269
+ allowed_engines=[WebSearchEngine.GOOGLE_LIGHT, WebSearchEngine.BING],
270
+ default_engine=WebSearchEngine.GOOGLE_LIGHT,
271
+ )
272
+ ```
273
+
274
+ `google_light` is the default because it is a fast general-purpose web search.
275
+ Yahoo is routed through its native `p` query parameter; the other supported web
276
+ engines use `q`.
277
+
278
+ ### News, maps, images, and videos
279
+
280
+ ```python
281
+ from serpapi_search_tools import images_search, maps_search, news_search, videos_search
282
+
283
+ tools = [
284
+ news_search(),
285
+ maps_search(),
286
+ images_search(),
287
+ videos_search(),
288
+ ]
289
+ ```
290
+
291
+ `news_search` supports keyword searches in Google News. `maps_search` searches
292
+ Google Maps and accepts optional `location`, `zoom` (`3` through `30`), and
293
+ `nearby` fields. Place details, reviews, and directions use different SerpApi
294
+ APIs and are not part of this search tool.
295
+
296
+ ### Shopping
297
+
298
+ ```python
299
+ from serpapi_search_tools import ShoppingSearchEngine, shopping_search
300
+
301
+ tool = shopping_search(
302
+ allowed_engines=[
303
+ ShoppingSearchEngine.GOOGLE_SHOPPING,
304
+ ShoppingSearchEngine.AMAZON,
305
+ ShoppingSearchEngine.WALMART,
306
+ ShoppingSearchEngine.EBAY,
307
+ ],
308
+ )
309
+ ```
310
+
311
+ The package routes one human `query` to each marketplace's native field:
312
+ Google Shopping uses `q`, Amazon uses `k`, Walmart uses `query`, and eBay uses
313
+ `_nkw`.
314
+
315
+ ### Hotels
316
+
317
+ ```python
318
+ from serpapi_search_tools import hotels_search
319
+
320
+ hotels = hotels_search(provider="function")
321
+ result = hotels(
322
+ query="hotels in Kyoto",
323
+ check_in_date="2026-08-01",
324
+ check_out_date="2026-08-04",
325
+ adults=2,
326
+ children=1,
327
+ children_ages=[8],
328
+ )
329
+ ```
330
+
331
+ Hotel dates use `YYYY-MM-DD`. Checkout must be after check-in. When `children`
332
+ is nonzero, provide exactly one age from 1 through 17 per child.
333
+
334
+ ### Flights
335
+
336
+ ```python
337
+ from serpapi_search_tools import TravelClass, flights_search
338
+
339
+ flights = flights_search(provider="function")
340
+ result = flights(
341
+ departure_id="LAX",
342
+ arrival_id="AUS",
343
+ outbound_date="2026-08-01",
344
+ return_date="2026-08-04",
345
+ travel_class=TravelClass.BUSINESS,
346
+ adults=1,
347
+ )
348
+ ```
349
+
350
+ `flights_search` requires an origin, destination, and outbound date. Omitting
351
+ `return_date` creates a one-way request; including it creates a round trip.
352
+ Multi-city searches are not currently supported.
353
+
354
+ ### Explore destinations
355
+
356
+ ```python
357
+ from serpapi_search_tools import travel_explore_search
358
+
359
+ explore = travel_explore_search(provider="function")
360
+ result = explore(
361
+ departure_id="JFK",
362
+ arrival_area_id="/m/02j9z",
363
+ )
364
+ ```
365
+
366
+ Travel Explore requires only a departure identifier. It can also accept an
367
+ arrival identifier or area, fixed outbound/return dates, cabin class, and
368
+ passenger counts. These travel tools send their route and date fields directly
369
+ to the matching SerpApi endpoint.
370
+
371
+ ## Set advanced parameters in application code
372
+
373
+ Use `default_params` for documented SerpApi settings that should stay under
374
+ your application's control, such as locale, currency, safe search, or result
375
+ count. The agent continues to supply only the inputs described by its search
376
+ tool.
377
+
378
+ Applications can supply documented advanced options at construction time:
379
+
380
+ ```python
381
+ tool = news_search(
382
+ default_params={"hl": "en", "gl": "us"},
383
+ )
384
+ ```
385
+
386
+ Typed fields and the constructor-controlled engine override colliding entries
387
+ in `default_params`. Known incompatible combinations are rejected locally, such
388
+ as Google News query plus topic tokens, Amazon keyword search plus `node`, or
389
+ flight airline include plus exclude filters.
390
+ For a multi-engine tool, the same defaults are sent to every allowed engine.
391
+ Use only parameters shared by those engines, or create separate tool instances
392
+ when each engine needs different defaults.
393
+ Reserved keys (`api_key`, `async`, `engine`, and `output`) are rejected in
394
+ `default_params`; use the constructor options documented below instead.
395
+
396
+ ## Handle search failures
397
+
398
+ The built-in client raises `SerpApiSearchError` when SerpApi rejects or cannot
399
+ complete a request. Its message is sanitized so an API key embedded in an
400
+ upstream request URL is replaced with `[REDACTED]`:
401
+
402
+ ```python
403
+ from serpapi_search_tools import SerpApiSearchError, web_search
404
+
405
+ search = web_search(provider="function")
406
+ try:
407
+ result = search(query="Python packaging")
408
+ except SerpApiSearchError as exc:
409
+ print(f"Search failed: {exc}")
410
+ ```
411
+
412
+ Local input errors such as invalid dates or incompatible parameters remain
413
+ `ValueError`, so applications can distinguish validation from provider and
414
+ transport failures.
415
+
416
+ ## Common factory options
417
+
418
+ Every constructor accepts:
419
+
420
+ | Option | Purpose |
421
+ | --- | --- |
422
+ | `provider` | Defaults to `"auto"`; select an SDK explicitly in multi-SDK environments or use `"function"` for a plain callable |
423
+ | `include_examples` | Include or omit a short example in the model description |
424
+ | `api_key` | Explicit SerpApi key |
425
+ | `client` | Custom object with `search(params)` for caching, interception, or tests |
426
+ | `default_params` | Application-controlled SerpApi options |
427
+ | `timeout` | Timeout passed to the SerpApi SDK client |
428
+ | `name` | Tool name presented to the model |
429
+ | `mode` | Result detail level: `"compact"` (default) or `"full"` |
430
+
431
+ `web_search` and `shopping_search` additionally accept `allowed_engines` and
432
+ `default_engine`. The tool offers only the engine values you configured.
433
+
434
+ ## Supported engine documentation
435
+
436
+ - [Google Search](https://serpapi.com/search-api)
437
+ - [Google Light](https://serpapi.com/google-light-api)
438
+ - [Bing](https://serpapi.com/bing-search-api)
439
+ - [Yahoo](https://serpapi.com/yahoo-search-api)
440
+ - [DuckDuckGo](https://serpapi.com/duckduckgo-search-api)
441
+ - [Google News](https://serpapi.com/google-news-api)
442
+ - [Google Maps](https://serpapi.com/google-maps-api)
443
+ - [Google Images](https://serpapi.com/google-images-api)
444
+ - [Google Shopping](https://serpapi.com/google-shopping-api)
445
+ - [Amazon](https://serpapi.com/amazon-search-api)
446
+ - [Walmart](https://serpapi.com/walmart-search-api)
447
+ - [eBay](https://serpapi.com/ebay-search-api)
448
+ - [YouTube](https://serpapi.com/youtube-search-api)
449
+ - [Google Hotels](https://serpapi.com/google-hotels-api)
450
+ - [Google Flights](https://serpapi.com/google-flights-api)
451
+ - [Google Travel Explore](https://serpapi.com/google-travel-explore-api)
452
+
453
+ SerpApi's complete documentation index is available in
454
+ [`llms.txt`](https://serpapi.com/llms.txt).
455
+
456
+ ## More guides
457
+
458
+ - [Introduction](https://serpapi.github.io/serpapi-search-tools-python/user-guide/introduction.html)
459
+ - [Quickstart](https://serpapi.github.io/serpapi-search-tools-python/user-guide/quickstart.html)
460
+ - [Choose a search tool](https://serpapi.github.io/serpapi-search-tools-python/user-guide/search_tools.html)
461
+ - [Usage and composition](https://serpapi.github.io/serpapi-search-tools-python/user-guide/usage.html)
462
+ - [Configuration](https://serpapi.github.io/serpapi-search-tools-python/user-guide/configuration.html)
463
+ - [Recipes](https://serpapi.github.io/serpapi-search-tools-python/user-guide/recipes.html)
464
+ - [Agent SDKs](https://serpapi.github.io/serpapi-search-tools-python/user-guide/frameworks.html)
465
+ - [Agent cookbook](https://serpapi.github.io/serpapi-search-tools-python/docs/cookbook/)
466
+ - [Runnable examples](https://serpapi.github.io/serpapi-search-tools-python/docs/sdk-examples/)