Exa Python SDK
The official Python SDK for Exa, the web search API for AI. It enables developers to semantically search the web, retrieve page contents, find similar pages, and generate answers with citations. The library is currently at version 2.11.0 and is actively maintained with regular updates.
Warnings
- breaking The library was formerly known as `metaphor-python`. While the API is largely compatible, existing `metaphor-python` installations should be migrated to `exa-py`.
- gotcha When using the `search` method with `output_schema`, avoid including citation or confidence fields directly in the schema. Grounding is returned automatically in the `output.grounding` field.
- gotcha By default, content retrieval (e.g., via `search` or `get_contents`) returns text with a maximum of 10,000 characters. To disable content retrieval or specify different options (like highlights or summary), use the `contents` parameter.
- gotcha For searches of `type: "object"` with `output_schema`, there are current limitations on the complexity of the output schema: a maximum nesting depth of 2 and a maximum of 10 total properties are enforced.
Install
-
pip install exa-py
Imports
- Exa
from exa_py import Exa
- AsyncExa
from exa_py import AsyncExa
Quickstart
import os
from exa_py import Exa
exa = Exa(api_key=os.environ.get('EXA_API_KEY', ''))
if exa.api_key:
# Search the web
results = exa.search(
"blog post about artificial intelligence",
type="auto",
contents={"highlights": True}
)
print("Search results:", results.results)
# Ask a question
response = exa.answer("What is the capital of France?")
print("Answer:", response.answer)
else:
print("EXA_API_KEY environment variable not set. Please set it to run the quickstart example.")