Tavily Python SDK
The `tavily-python` library provides a Python wrapper for the Tavily API, enabling easy integration of web search, content extraction, crawling, mapping, and research functionalities into Python applications. It supports both synchronous and asynchronous clients. The library is under active development with frequent updates, with its current version being 0.7.23.
Warnings
- deprecated The `langchain_community.tools.tavily_search.tool` has been deprecated in favor of the new `langchain-tavily` Python package. This new package supports Search, Extract, Map, and Crawl functionality and receives continuous updates.
- gotcha Failure to provide a valid Tavily API key during client instantiation will result in a `tavily.MissingAPIKeyError`. The API key is essential for all API interactions.
- gotcha Intermittent HTTP 400 Client Errors or 500 Server Errors have been reported by users, often related to API outages or invalid/expired API keys.
- gotcha Using `auto_parameters=True` in the `search` method might automatically set `search_depth` to `advanced`, which can consume more API credits (2 API credits instead of 1 for `basic`).
Install
-
pip install tavily-python
Imports
- TavilyClient
from tavily import TavilyClient
- AsyncTavilyClient
from tavily import AsyncTavilyClient
- MissingAPIKeyError
from tavily import MissingAPIKeyError
Quickstart
import os
from tavily import TavilyClient
tavily_client = TavilyClient(api_key=os.environ.get('TAVILY_API_KEY', ''))
if not tavily_client.api_key:
raise ValueError("TAVILY_API_KEY environment variable not set. Get your key from tavily.com.")
response = tavily_client.search("What is the capital of France?")
print(response)