Skip to Content
AeroSearch Docs
Quickstarts

Python quickstart

Call Collection search or Answers from Python and receive a 200 in under five minutes.

Goal: call the Search API from Python and receive HTTP 200 with a queryId in under five minutes. The sample below uses the wire contract from OpenAPI; production code may use the published aerosearch-sdk package.

Set AEROSEARCH_BASE_URL to your Cell search host (without a route), AEROSEARCH_API_KEY to a Project search key, and AEROSEARCH_COLLECTION to its Collection id. Set AEROSEARCH_END_USER_TOKEN only when your server supplies a real end-user token.

Sample

# generated-from-contract: contracts/openapi/v1.yaml
# Python SDK / stdlib — searchCollectionPost
# POST /v1/collections/col_help/search  (SearchRequest)

import os
import urllib.request
import json

BASE = os.environ.get("AEROSEARCH_BASE_URL", "https://api.aerosearch.team").rstrip("/").removesuffix("/v1")
COLLECTION = os.environ.get("AEROSEARCH_COLLECTION", "col_help")
API_KEY = os.environ.get("AEROSEARCH_API_KEY", "ask_YOUR_PROJECT_SEARCH_KEY")
url = f"{BASE}/v1/collections/{COLLECTION}/search"
body = json.dumps({"query": "reset password", "limit": 10}).encode()

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json",
}
end_user_token = os.environ.get("AEROSEARCH_END_USER_TOKEN")
if end_user_token:
    headers["X-AeroSearch-End-User-Token"] = end_user_token

req = urllib.request.Request(url, data=body, method="POST", headers=headers)
with urllib.request.urlopen(req) as res:
    print(json.dumps(json.loads(res.read().decode())))

Verify

From this repository, the local double verification executes the generated sample:

AEROSEARCH_BASE_URL=http://127.0.0.1:4418 AEROSEARCH_API_KEY=ask_search AEROSEARCH_COLLECTION=col_quickstart \
node tests/harness/quickstarts-daily/run.mjs python

On this page