tavily-python 0.5.1__tar.gz → 0.5.3__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.
Files changed (20) hide show
  1. {tavily_python-0.5.1/tavily_python.egg-info → tavily_python-0.5.3}/PKG-INFO +87 -69
  2. {tavily_python-0.5.1 → tavily_python-0.5.3}/README.md +85 -68
  3. {tavily_python-0.5.1 → tavily_python-0.5.3}/setup.py +1 -1
  4. {tavily_python-0.5.1 → tavily_python-0.5.3}/tavily/async_tavily.py +87 -37
  5. {tavily_python-0.5.1 → tavily_python-0.5.3}/tavily/errors.py +8 -2
  6. {tavily_python-0.5.1 → tavily_python-0.5.3}/tavily/tavily.py +79 -37
  7. {tavily_python-0.5.1 → tavily_python-0.5.3/tavily_python.egg-info}/PKG-INFO +87 -69
  8. {tavily_python-0.5.1 → tavily_python-0.5.3}/tests/test_async_search.py +0 -1
  9. {tavily_python-0.5.1 → tavily_python-0.5.3}/LICENSE +0 -0
  10. {tavily_python-0.5.1 → tavily_python-0.5.3}/setup.cfg +0 -0
  11. {tavily_python-0.5.1 → tavily_python-0.5.3}/tavily/__init__.py +0 -0
  12. {tavily_python-0.5.1 → tavily_python-0.5.3}/tavily/config.py +0 -0
  13. {tavily_python-0.5.1 → tavily_python-0.5.3}/tavily/hybrid_rag/__init__.py +0 -0
  14. {tavily_python-0.5.1 → tavily_python-0.5.3}/tavily/hybrid_rag/hybrid_rag.py +0 -0
  15. {tavily_python-0.5.1 → tavily_python-0.5.3}/tavily/utils.py +0 -0
  16. {tavily_python-0.5.1 → tavily_python-0.5.3}/tavily_python.egg-info/SOURCES.txt +0 -0
  17. {tavily_python-0.5.1 → tavily_python-0.5.3}/tavily_python.egg-info/dependency_links.txt +0 -0
  18. {tavily_python-0.5.1 → tavily_python-0.5.3}/tavily_python.egg-info/requires.txt +0 -0
  19. {tavily_python-0.5.1 → tavily_python-0.5.3}/tavily_python.egg-info/top_level.txt +0 -0
  20. {tavily_python-0.5.1 → tavily_python-0.5.3}/tests/test_sync_search.py +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: tavily-python
3
- Version: 0.5.1
3
+ Version: 0.5.3
4
4
  Summary: Python wrapper for the Tavily API
5
5
  Home-page: https://github.com/tavily-ai/tavily-python
6
6
  Author: Tavily AI
@@ -20,12 +20,13 @@ Dynamic: classifier
20
20
  Dynamic: description
21
21
  Dynamic: description-content-type
22
22
  Dynamic: home-page
23
+ Dynamic: license-file
23
24
  Dynamic: requires-dist
24
25
  Dynamic: requires-python
25
26
  Dynamic: summary
26
27
 
27
-
28
28
  # Tavily Python Wrapper
29
+
29
30
  The Tavily Python wrapper allows for easy interaction with the Tavily API, offering the full range of our search and extract functionalities directly from your Python programs. Easily integrate smart search and content extraction capabilities into your applications, harnessing Tavily's powerful search and extract features.
30
31
 
31
32
  ## Installing
@@ -37,6 +38,7 @@ pip install tavily-python
37
38
  # Tavily Search
38
39
 
39
40
  ## Usage
41
+
40
42
  Below are some code snippets that show you how to interact with our search API. The different steps and components of this code are explained in more detail in the API Methods section further down.
41
43
 
42
44
  ### Getting and printing the full Search API response
@@ -53,6 +55,7 @@ response = tavily_client.search("Who is Leo Messi?")
53
55
  # Step 3. That's it! You've done a Tavily Search!
54
56
  print(response)
55
57
  ```
58
+
56
59
  This is equivalent to directly querying our REST API.
57
60
 
58
61
  ### Generating context for a RAG Application
@@ -69,6 +72,7 @@ context = tavily_client.get_search_context(query="What happened during the Burni
69
72
  # Step 3. That's it! You now have a context string that you can feed directly into your RAG Application
70
73
  print(context)
71
74
  ```
75
+
72
76
  This is how you can generate precise and fact-based context for your RAG application in one line of code.
73
77
 
74
78
  ### Getting a quick answer to a question
@@ -85,9 +89,10 @@ answer = tavily_client.qna_search(query="Who is Leo Messi?")
85
89
  # Step 3. That's it! Your question has been answered!
86
90
  print(answer)
87
91
  ```
92
+
88
93
  This is how you get accurate and concise answers to questions, in one line of code. Perfect for usage by LLMs!
89
94
 
90
- ## API Methods
95
+ ## API Methods
91
96
 
92
97
  ### Client
93
98
 
@@ -95,60 +100,63 @@ This is how you get accurate and concise answers to questions, in one line of co
95
100
 
96
101
  The `TavilyClient` class is the entry point to interacting with the Tavily API. Kickstart your journey by instantiating it with your API key. If you want to use Tavily asynchronously, you will need to instantiate an `AsyncTavilyClient` instead.
97
102
 
98
- Once you do so, you're ready to search the Web in one line of code! All you need is to pass a `str` as a `query` to one of our methods (detailed below) and you'll start searching!
103
+ If you want to use either client with specified HTTP or HTTPS proxies, you can do so by passing the proxies parameter as a dictionary in the format `{ "http": str, "https": str }`, where each key is optional, or by setting the `TAVILY_HTTP_PROXY` or `TAVILY_HTTPS_PROXY` environment variables.
104
+
105
+ Once you've instantiated your client, you're ready to search the Web in one line of code! All you need is to pass a `str` as a `query` to one of our methods (detailed below) and you'll start searching!
99
106
 
100
107
  ### Methods
101
- * **`search`**(query, **kwargs)
102
- * Performs a Tavily Search query and returns the response as a well-structured `dict`.
103
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `days`, `time_range`, `max_results`, `include_domains`, `exclude_domains`, `include_answer`, `include_raw_content`, `include_images`, `include_image_descriptions`.
104
- * **Returns** a `dict` with all related response fields. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `dict`. The details of the exact response format are given in the Search Responses section further down.
105
-
106
- * **`get_search_context`**(query, **kwargs)
107
- * Performs a Tavily Search query and returns a `str` of content and sources within the provided token limit. It's useful for getting only related content from retrieved websites without having to deal with context extraction and token management.
108
- * The **core parameter** for this function is `max_tokens`, an `int`. It defaults to `4000`. It is provided as a keyword argument.
109
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `days`, `time_range`, `max_results`, `include_domains`, `exclude_domains`.
110
- * **Returns** a `str` containing the content and sources of the results. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
111
-
112
- * **`qna_search`**(query, **kwargs)
113
- * Performs a search and returns a string containing an answer to the original query. This is optimal to be used as a tool for AI agents.
114
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth` (defaults to `"advanced"`), `topic`, `days`, `time_range`, `time_range`, `max_results`, `include_domains`, `exclude_domains`.
115
- * **Returns** a `str` containing a short answer to the search query. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
108
+
109
+ - **`search`**(query, \*\*kwargs)
110
+ - Performs a Tavily Search query and returns the response as a well-structured `dict`.
111
+ - **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `days`, `time_range`, `max_results`, `include_domains`, `exclude_domains`, `include_answer`, `include_raw_content`, `include_images`, `include_image_descriptions`.
112
+ - **Returns** a `dict` with all related response fields. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `dict`. The details of the exact response format are given in the Search Responses section further down.
113
+ - **`get_search_context`**(query, \*\*kwargs)
114
+
115
+ - Performs a Tavily Search query and returns a `str` of content and sources within the provided token limit. It's useful for getting only related content from retrieved websites without having to deal with context extraction and token management.
116
+ - The **core parameter** for this function is `max_tokens`, an `int`. It defaults to `4000`. It is provided as a keyword argument.
117
+ - **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth`, `topic`, `days`, `time_range`, `max_results`, `include_domains`, `exclude_domains`.
118
+ - **Returns** a `str` containing the content and sources of the results. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
119
+
120
+ - **`qna_search`**(query, \*\*kwargs)
121
+ - Performs a search and returns a string containing an answer to the original query. This is optimal to be used as a tool for AI agents.
122
+ - **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `search_depth` (defaults to `"advanced"`), `topic`, `days`, `time_range`, `time_range`, `max_results`, `include_domains`, `exclude_domains`.
123
+ - **Returns** a `str` containing a short answer to the search query. If you decide to use the asynchronous client, returns a `coroutine` resolving to that `str`.
116
124
 
117
125
  ### Keyword Arguments (optional)
118
126
 
119
- * **`search_depth`: str** - The depth of the search. It can be `"basic"` or `"advanced"`. Default is `"basic"` unless specified otherwise in a given method.
127
+ - **`search_depth`: str** - The depth of the search. It can be `"basic"` or `"advanced"`. Default is `"basic"` unless specified otherwise in a given method.
120
128
 
121
- * **`topic`: str** - The category of the search. This will determine which of our agents will be used for the search. Currently, only `"general"` and `"news"` are supported. Default is `"general"`.
129
+ - **`topic`: str** - The category of the search. This will determine which of our agents will be used for the search. Currently, only `"general"` and `"news"` are supported. Default is `"general"`.
122
130
 
123
- * **`days`: int** - The number of days back from the current date to include in the search results. This specifies the time frame of data to be retrieved. Please note that this feature is only available when using the `"news"` search `topic`. Default is `3`.
131
+ - **`days`: int** - The number of days back from the current date to include in the search results. This specifies the time frame of data to be retrieved. Please note that this feature is only available when using the `"news"` search `topic`. Default is `3`.
124
132
 
125
- * **`time_range`: str** - The time range back from the current date to include in the search results. Accepted values include `"day"`,`"week"`,`"month"`,`"year"` or `"d"`,`"w"`,`"m"`,`"y"`. Default is `None`, which will not filter search results by time range.
133
+ - **`time_range`: str** - The time range back from the current date to include in the search results. Accepted values include `"day"`,`"week"`,`"month"`,`"year"` or `"d"`,`"w"`,`"m"`,`"y"`. Default is `None`, which will not filter search results by time range.
126
134
 
127
- * **`max_results`: int** - The maximum number of search results to return. Default is `5`.
135
+ - **`max_results`: int** - The maximum number of search results to return. Default is `5`.
128
136
 
129
- * **`include_images`: bool** - Include a list of query-related images in the response. Default is `False`.
137
+ - **`include_images`: bool** - Include a list of query-related images in the response. Default is `False`.
130
138
 
131
- * **`include_image_descriptions`: bool** - When `include_images` is set to `True`, this option adds descriptive text for each image. Default is `False`.
139
+ - **`include_image_descriptions`: bool** - When `include_images` is set to `True`, this option adds descriptive text for each image. Default is `False`.
132
140
 
133
- * **`include_answer`: bool | str** - Include an answer to original query, generated by an LLM based on Tavily's search results. `"basic"`/`True` answer will be quick but less detailed, `"advanced"` answer will be more detailed but take longer to generate. Default is `False`.
141
+ - **`include_answer`: bool | str** - Include an answer to original query, generated by an LLM based on Tavily's search results. `"basic"`/`True` answer will be quick but less detailed, `"advanced"` answer will be more detailed but take longer to generate. Default is `False`.
134
142
 
135
- * **`include_raw_content`: bool** - Include the cleaned and parsed HTML content of each search result. Default is `False`.
143
+ - **`include_raw_content`: bool** - Include the cleaned and parsed HTML content of each search result. Default is `False`.
136
144
 
137
- * **`include_domains`: list[str]** - A list of domains to specifically include in the search results. Default is `None`, which includes all domains.
145
+ - **`include_domains`: list[str]** - A list of domains to specifically include in the search results. Default is `None`, which includes all domains.
138
146
 
139
- * **`exclude_domains`: list[str]** - A list of domains to specifically exclude from the search results. Default is `None`, which doesn't exclude any domains.
147
+ - **`exclude_domains`: list[str]** - A list of domains to specifically exclude from the search results. Default is `None`, which doesn't exclude any domains.
140
148
 
141
149
  ### Search Responses
142
150
 
143
- * **`answer`: str**- The answer to your search query. This will be `None` unless `include_answer` is set to `True`, `"basic"` or `"advanced"`.
151
+ - **`answer`: str**- The answer to your search query. This will be `None` unless `include_answer` is set to `True`, `"basic"` or `"advanced"`.
144
152
 
145
- * **`query`: str** - Your search query.
153
+ - **`query`: str** - Your search query.
146
154
 
147
- * **`response_time`: float** - Your search result response time.
155
+ - **`response_time`: float** - Your search result response time.
148
156
 
149
- * **`images`: list[str | dict]** - A list of query-related image URLs. If `include_image_descriptions` is set to `True` each entry will be a dictionary with `url` and `description`
157
+ - **`images`: list[str | dict]** - A list of query-related image URLs. If `include_image_descriptions` is set to `True` each entry will be a dictionary with `url` and `description`
150
158
 
151
- * **`results`: list** - A list of sorted search results ranked by relevancy. Each result is in the following format:
159
+ - **`results`: list** - A list of sorted search results ranked by relevancy. Each result is in the following format:
152
160
  - **`title`: str** - The title of the search result URL.
153
161
  - **`url`: str** - The URL of the search result.
154
162
  - **`content`: str** - The most query related content from the scraped URL. We use proprietary AI and algorithms to extract only the most relevant content from each URL, to optimize for context quality and size.
@@ -156,7 +164,6 @@ Once you do so, you're ready to search the Web in one line of code! All you need
156
164
  - **`score`: float** - The relevance score of the search result.
157
165
  - **`published_date`: str (optional)** - The publication date of the source. This is only available if you are using `"news"` as your search `topic`.
158
166
 
159
-
160
167
  When you send a search query, the response `dict` you receive will be in the following format:
161
168
 
162
169
  ```python
@@ -164,10 +171,10 @@ response = {
164
171
  "query": "The query provided in the request",
165
172
  "answer": "A short answer to the query", # This will be None if include_answer is set to False in the request
166
173
  "follow_up_questions": None, # This feature is still in development
167
- "images": [
174
+ "images": [
168
175
  {
169
176
  "url": "Image 1 URL",
170
- "description": "Image 1 Description",
177
+ "description": "Image 1 Description",
171
178
  },
172
179
  {
173
180
  "url": "Image 2 URL",
@@ -203,6 +210,7 @@ response = {
203
210
  "response_time": 1.09 # This will be your search response time
204
211
  }
205
212
  ```
213
+
206
214
  # Tavily Extract
207
215
 
208
216
  ## Usage
@@ -238,7 +246,7 @@ for result in response["results"]:
238
246
  # Note that URLs that could not be extracted will be stored in response["failed_results"]
239
247
  ```
240
248
 
241
- ## API Methods
249
+ ## API Methods
242
250
 
243
251
  ### Client
244
252
 
@@ -248,33 +256,38 @@ The `TavilyClient` class is your entry point to interacting with the Tavily API.
248
256
 
249
257
  If you want to use Tavily asynchronously, you will need to instantiate an `AsyncTavilyClient` instead. The asynchronous client's interface is identical to the synchronous client's, the only difference being that all methods are asynchronous.
250
258
 
259
+ ### Proxies
260
+
261
+ If you want to use either client with specified HTTP or HTTPS proxies, you can do so by passing the proxies parameter as a dictionary in the format `{ "http": str, "https": str }`, where each key is optional, or by setting the `TAVILY_HTTP_PROXY` or `TAVILY_HTTPS_PROXY` environment variables.
262
+
251
263
  ### Methods
252
264
 
253
- * **`extract`**(urls, **kwargs)
254
- * Extracts the raw content from a given list of URLs (or a single URL string) and returns the response as a
255
- well-structured `dict`.
256
- * **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `include_images`
257
- * **Returns** a `dict` with all related response fields. If using the asynchronous client, it returns a coroutine
265
+ - **`extract`**(urls, \*\*kwargs)
266
+ - Extracts the raw content from a given list of URLs (or a single URL string) and returns the response as a
267
+ well-structured `dict`.
268
+ - **Additional parameters** can be provided as keyword arguments (detailed below). The keyword arguments supported by this method are: `include_images`
269
+ - **Returns** a `dict` with all related response fields. If using the asynchronous client, it returns a coroutine
258
270
  that resolves to this `dict`. For details on the response format, see the Extract Responses section.
259
-
271
+
260
272
  ### Keyword Arguments (optional)
261
273
 
262
- * **`include_images`: bool** - Include a list of images extracted from the `urls` in the response. Default is `False`.
274
+ - **`include_images`: bool** - Include a list of images extracted from the `urls` in the response. Default is `False`.
263
275
 
264
276
  ### Extract Responses
265
277
 
266
- * **`results`: list**: A list of extracted content from the provided URLs. Each result is in the following format:
278
+ - **`results`: list**: A list of extracted content from the provided URLs. Each result is in the following format:
279
+
267
280
  - **`url`: str** - The URL of the webpage from which content was extracted.
268
281
  - **`raw_content`- str** - The raw content extracted from the provided URL.
269
282
  - **`images`: list[str]** - A list of extracted image URLs.
270
- ``
283
+ ``
284
+
285
+ - **`failed_results`: list** - A list of URLs that could not be processed, if any. Each result is in the following format:
271
286
 
272
- * **`failed_results`: list** - A list of URLs that could not be processed, if any. Each result is in the following format:
273
287
  - **`url`: str** - The URL that failed to be processed.
274
288
  - **`error`: str** - An error message describing why the URL could not be processed.
275
-
276
289
 
277
- * **`response_time`: float** - Your search result response time.
290
+ - **`response_time`: float** - Your search result response time.
278
291
 
279
292
  When you send a URL or a list of URLs, the response `dict` you receive will be in the following format:
280
293
 
@@ -303,12 +316,12 @@ When you send a URL or a list of URLs, the response `dict` you receive will be i
303
316
  }
304
317
  ```
305
318
 
306
- ## Error Handling
319
+ ## Error Handling
307
320
 
308
321
  The Tavily Python SDK includes comprehensive error handling to ensure smooth interaction with the API. Below are the specific exceptions that might be raised during usage:
309
322
 
310
323
  1. **Missing API Key**: If no API key is provided when initializing the `TavilyClient`, a `tavily.MissingAPIKeyError` will be raised. Ensure you pass a valid API key to the `TavilyClient` during instantiation.
311
-
324
+
312
325
  ```python
313
326
  from tavily import TavilyClient, MissingAPIKeyError
314
327
 
@@ -343,16 +356,18 @@ The Tavily Python SDK includes comprehensive error handling to ensure smooth int
343
356
  except UsageLimitExceededError:
344
357
  print("Usage limit exceeded. Please check your plan's usage limits or consider upgrading.")
345
358
  ```
346
- These errors ensure that you are aware of the specific issues related to your API key usage, allowing you to take appropriate actions to resolve them.
347
359
 
360
+ These errors ensure that you are aware of the specific issues related to your API key usage, allowing you to take appropriate actions to resolve them.
348
361
 
349
362
  4. **Bad Request Errors**: The `/extract` endpoint may return a `tavily.BadRequestError` in the following cases:
363
+
350
364
  - **Exceeds URL Limit**: If the number of URLs in the request exceeds the maximum allowed limit of 20, a `tavily.BadRequestError` will be raised.
365
+
351
366
  ```python
352
367
  from tavily import TavilyClient, BadRequestError
353
-
368
+
354
369
  tavily_client = TavilyClient(api_key="valid-api-key")
355
-
370
+
356
371
  urls = [
357
372
  "https://en.wikipedia.org/wiki/Artificial_intelligence",
358
373
  "https://en.wikipedia.org/wiki/Machine_learning",
@@ -380,28 +395,31 @@ The Tavily Python SDK includes comprehensive error handling to ensure smooth int
380
395
  response = tavily_client.extract(urls=urls)
381
396
  except BadRequestError as e:
382
397
  print(e)
383
- ```
398
+ ```
399
+
384
400
  - **Validation Failure:** If all URLs provided in the request fail validation, a `tavily.BadRequestError` will be raised with details on the failed URLs.
401
+
385
402
  ```python
386
403
  from tavily import TavilyClient, BadRequestError
387
-
404
+
388
405
  tavily_client = TavilyClient(api_key="valid-api-key")
389
-
406
+
390
407
  try:
391
408
  response = tavily_client.extract(urls=["https://invalid-url1", "https://invalid-url2"])
392
409
  except BadRequestError as e:
393
410
  print(e)
394
- ```
411
+ ```
412
+
395
413
  These errors help you identify specific issues with your URLs, allowing you to take the necessary actions to resolve them.
396
414
 
397
- ## Tavily API Credit Deduction Overview
398
-
399
- * **Tavily Search**
400
- * Each basic search (`search_depth="basic"`) will deduct 1 API credit from your account.
401
- * Each advanced search (`search_depth="advanced"`) will deduct 2 API credits from your account.
402
- * **Tavily Extract**
403
- * For every 5 successful URL extractions, 1 API credit will be deducted from your account.
404
-
415
+ ## Tavily API Credit Deduction Overview
416
+
417
+ - **Tavily Search**
418
+ - Each basic search (`search_depth="basic"`) will deduct 1 API credit from your account.
419
+ - Each advanced search (`search_depth="advanced"`) will deduct 2 API credits from your account.
420
+ - **Tavily Extract**
421
+ - For every 5 successful URL extractions, 1 API credit will be deducted from your account.
422
+
405
423
  ## License
406
424
 
407
425
  This project is licensed under the terms of the MIT license.