Python SDK
Type-safe client with sync and async support. Works with Python 3.9+.
Installation
pip install canonical-search
Quick Start
from canonical_search import CanonicalClient client = CanonicalClient(api_key="sk_your_key") results = client.search("AI healthcare startups") for company in results.results: print(f"{company.name} — {company.domain}") print(f" {company.description[:100]}")
Configuration
Direct
client = CanonicalClient(
api_key="sk_your_key",
base_url="https://trycanonical.ai", # default
timeout=30.0, # default
)
Environment Variables
export CANONICAL_API_KEY=sk_your_key export CANONICAL_API_BASE_URL=https://trycanonical.ai # optional export CANONICAL_TIMEOUT=30.0 # optional
from canonical_search.config import client_from_env client = client_from_env() results = client.search("fintech companies in Europe")
Search Methods
Sync
results = client.search(
query="B2B SaaS companies",
top_k=50, # 1-100, default 20
verified=True, # LLM verification, default False
)
Async
results = await client.asearch( query="B2B SaaS companies", top_k=50, verified=True, )
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
| query | str | required | Natural language search query |
| top_k | int | 20 | Number of results (1–100) |
| verified | bool | False | LLM verification (uses 2 credits) |
Response Types
SearchResponse
class SearchResponse: results: list[Company] # Matching companies count: int # Number of results query: str # Original query credits_used: int # Credits consumed credits_remaining: int | None # Remaining credits
Company
class Company: id: int name: str website: str logo_url: str | None domain: str description: str verdict: str | None # Only when verified=True verdict_reason: str | None # Only when verified=True
Error Handling
from canonical_search import CanonicalClient from canonical_search.exceptions import ( AuthenticationError, RateLimitError, APIError, ) client = CanonicalClient(api_key="sk_your_key") try: results = client.search("fintech") except AuthenticationError: print("Invalid or missing API key") except RateLimitError: print("Rate limit exceeded — wait and retry") except APIError as e: print(f"API error: {e}")
| Exception | HTTP Status | Meaning |
|---|---|---|
| AuthenticationError | 401 | Invalid or missing API key |
| RateLimitError | 429 | Rate limit exceeded |
| APIError | 5xx | Server error |