SDKs
Official Python client for expand.ai
The Python SDK provides a clean, Pythonic interface for interacting with expand.ai's API.
pip install expandaiuv add expandaipoetry add expandai
from expandai import Expand
client = Expand(
# Your API key (required, or set EXPAND_API_KEY env var)
api_key="{{API_KEY}}",
# Custom base URL (optional)
base_url="https://api.expand.ai/v1",
# Additional headers (optional)
headers={
"Custom-Header": "value"
}
)Instead of passing the API key directly, you can set the EXPAND_API_KEY environment variable:
export EXPAND_API_KEY={{API_KEY}}# API key will be read from EXPAND_API_KEY
client = Expand()The SDK supports async/await for concurrent requests using AsyncExpand:
import asyncio
from expandai import AsyncExpand
async def main():
client = AsyncExpand(api_key="{{API_KEY}}")
result = await client.fetch(
url="https://example.com",
select={"markdown": True}
)
from expandai import Expand, ExpandError, APIError, RateLimitError
client = Expand(api_key="{{API_KEY}}")
try:
result = client.fetch(
url="https://example.com",
select={"markdown": True}
)
print(result.data.markdown)
except RateLimitError as e:
print(