AEO API Python SDK
Use AeoClient in scripts and synchronous applications. In an async application, use AsyncAeoClient and await the same methods. Both clients accept the same operation arguments.
Install the package
With Python 3.10 or later and Git installed, clone the Python SDK repository and install aeo-sdk from it with pip.
git clone https://github.com/aeo-api/aeoapi-python-sdk.git
python -m pip install ./aeoapi-python-sdkImport the package as aeo_sdk. Pip also installs its dependencies, including httpx 0.28 or later.
Create a client and read the account
Set AEO_API_BASE_URL to https://api.aeoapi.dev and AEO_API_KEY to your server's API key. The client adds the versioned path and sends the key in the Authorization header. This read requires account:read.
import os
from aeo_sdk import AeoClient
with AeoClient(os.environ["AEO_API_KEY"], base_url=os.environ["AEO_API_BASE_URL"]) as client:
response = client.v2_get_account()
print(response.data["plan"], response.request_id)The with block closes the client when it exits. For AsyncAeoClient, use async with and await client.v2_get_account(). If your application manages the client itself, call client.close() or await client.aclose() at shutdown. Both clients expose their configured origin as client.base_url.
Read a response
Each operation returns a Response with status, headers and body. The client parses JSON and returns CSV as text. For responses with a data field, response.data reads that field directly.
metaandwarnings- Metadata and warning messages from the response. Both are empty when absent.
request_id- Value of X-Request-ID. Include it when asking about a request.
etag- ETag header, when supplied. Pass its quoted numeric revision as
if_matchon operations that check it. usage_units- Integer from X-Usage-Units, or None if the header is absent or nonnumeric.
location- Location header, when present. Some run responses also include a poll URL in the body.
next_cursor- Next cursor in the metadata or X-Next-Cursor header. None marks the end of a cursor-based list.
Page through results or wait for a run
Use iter_items to process records, or iter_pages to inspect each response. For async iteration, use async for with aiter_items or aiter_pages. On an offset-based list, such as drafts, pass the returned next_offset yourself.
Call wait_for_run or await_run with a qualified run ID or poll URL. For Brave submissions, both helpers return at submitted or failed. To check the status yourself, follow the Brave polling example.
Handle errors and set timeouts
AeoApiError describes an API error response. Check code, status, retryable and field_errors. A ValidationError can identify the input that failed. AeoTransportError covers a transport failure after allowed retries or an unreadable JSON success response. Both inherit from AeoError.
The default connection and connection-pool timeouts are 5 seconds. Read and write timeouts are 30 seconds each. To change them, pass an httpx.Timeout when you construct the client.
import os
import httpx
from aeo_sdk import AeoApiError, AeoClient, RetryPolicy
timeout = httpx.Timeout(connect=5, read=15, write=15, pool=5)
with AeoClient(
os.environ["AEO_API_KEY"],
base_url=os.environ["AEO_API_BASE_URL"],
timeout=timeout,
retry=RetryPolicy(max_retries=1),
) as client:
try:
account = client.v2_get_account()
except AeoApiError as error:
print(error.status, error.code, error.request_id)
raise
print(account.status)Control retries
The default RetryPolicy allows two extra attempts for GET requests and writes whose selected operation requires Idempotency-Key. A write that merely accepts an optional key does not qualify. On qualifying writes, the client keeps the same key across retry attempts.
Retries apply to transport failures, HTTP 429 and retryable HTTP 503 responses. For a numeric Retry-After of up to 60 seconds, the client waits that long. It raises the error for longer waits. Without a delay from the API, it chooses a random delay up to the backoff limit, starting at 0.5 seconds and doubling to a cap of 8 seconds.
Set RetryPolicy(max_retries=0) to turn off retries. You can also set base_backoff, max_backoff and max_retry_after in seconds. For offline tests, pass an httpx.MockTransport as transport. The optional sleep and rng arguments control delays and randomness in tests.
Method reference
The examples use sample IDs, dates, revisions and content. Replace them with values from your account. The linked REST operation lists each request variant and its access requirements.