Skip to main content

Python wrapper for the Tavily API

Project description

This Python wrapper allows for easy interaction with the Tavily API, offering both basic and advanced search functionalities directly from your Python programs. Easily integrate smart search capabilities into your applications, harnessing Tavily’s powerful search features.

Installing

pip install tavily-python

Usage

from tavily import TavilyClient
tavily = TavilyClient(api_key="YOUR_API_KEY")
# For basic search:
tavily.search(query="Should I invest in Apple right now?")
# For advanced search:
tavily.search(query="Should I invest in Apple right now?", search_depth="advanced")

Additional Methods

# You can easily get search result context based on any max tokens straight into your RAG.
# The response is a string of the context within the max_token limit.
tavily.get_search_context(query="What happened in the burning man floods?", search_depth="advanced", max_tokens=1500)

# You can also get a simple answer to a question including relevant sources all with a simple function call:
tavily.qna_search(query="Where does Messi play right now?")

# By leveraging our topic API, you can search for an aggregation of company information such as news, financial and more in one call:
tavily.get_company_info(query="Information about Nvidia nvidia.com", search_depth="advanced", max_results=7)

API Methods

Client

The Client class is the entry point to interacting with the Tavily API. Kickstart your journey by instantiating it with your API key.

Methods

  • search(query, search_depth, **kwargs): Performs a search using the specified query. The depth of the search can be controlled by the search_depth parameter.

  • get_search_context(query, search_depth, max_tokens, **kwargs): Performs a search and returns a string of content and sources within token limit. Useful for getting only related content from retrieved websites without having to deal with context extraction and token management.

  • qna_search(query, **kwargs): Performs a search and returns a string containing an answer to the original query including relevant sources. Optimal to be used as a tool for AI agents.

  • get_company_info(query, **kwargs): Performs a cross topic (news, financial, etc) search about a given company.

Keyword Arguments

  • search_depth (str): The depth of the search. It can be “basic” or “advanced”. Default is “basic”.

  • topic (str): The topic of the search - can be “general”, “finance”, “code”, and “news”. Default is “general”.

  • max_results (int): The number of search results to return. Default is 10.

  • include_domains (list): A list of domains to specifically include in the search results. Default is None, which includes all domains.

  • exclude_domains (list): A list of domains to specifically exclude from the search results. Default is None, which doesn’t exclude any domains.

  • include_answer (bool): Whether or not to include answers in the search results. Default is False.

  • include_raw_content (bool): Whether or not to include raw content in the search results. Default is False.

  • include_images (bool): Whether or not to include images in the search results. Default is False.

  • use_cache (bool): Whether or not to use tavily’s cache for faster results. Default is True.

Both methods internally call the _search method to communicate with the API.

Error Handling

In case of an unsuccessful HTTP request, a HTTPError will be raised.

License

This project is licensed under the terms of the MIT license.

Contact

For questions, support, or to learn more, please visit Tavily.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tavily-python-0.2.8.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tavily_python-0.2.8-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file tavily-python-0.2.8.tar.gz.

File metadata

  • Download URL: tavily-python-0.2.8.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for tavily-python-0.2.8.tar.gz
Algorithm Hash digest
SHA256 12c8588ea70d59d27cc5320988bc03e534bd8dded9a5dd01e6debea643a00c91
MD5 8ab181d3330589dd0906e26bb025e4a9
BLAKE2b-256 a7c1b74787b1ac74b4fd079aaa5e8c92ef84c7e9c6e5147b8dd4b5512f6cce82

See more details on using hashes here.

File details

Details for the file tavily_python-0.2.8-py3-none-any.whl.

File metadata

  • Download URL: tavily_python-0.2.8-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.12

File hashes

Hashes for tavily_python-0.2.8-py3-none-any.whl
Algorithm Hash digest
SHA256 5ad181c810fcf6ea83d5e436518aa0ccea7a7efba048577fb5b6f6576009490d
MD5 b91aa628968d5d32ac113a5dfd8967b8
BLAKE2b-256 c91b04eeac36d5e46ca7f152d8e096ed4967db6f504c80bfc9619982e9f79e58

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page