Python
The official Python SDK (spyglass-sdk on PyPI, spyglass-so/spyglass-python on GitHub) provides typed synchronous (Spyglass) and asynchronous (AsyncSpyglass) clients for the Spyglass API.
Installation
Install spyglass-sdk with pip or uv:
Usage
- Get an API key from Settings → API in the dashboard.
- Set the key as an environment variable named
SPYGLASS_API_KEYor pass it directly to theSpyglassclass astoken.
Searching Brands & Creators
Search brands
Search brands by name (names), social handle (ig_username, tiktok_username), known IDs (brand_ids), or a natural-language brief (query):
Search creators
Search creators by handle, name, or natural-language brief, and filter by demographic and profile attributes (gender, age_range, ethnicity, location, language):
Searching Ad Creatives & Social Media
Pass account_id to inspect a specific brand or creator’s creatives, or omit account_id and pass query to search across the entire Spyglass index:
Insights, Campaigns, Landing Pages & Comments
Creative insights, campaigns, and landing pages
Pull clustered creative themes (HOOK, USP, PERSONA, MEDIA_MIX), campaigns or offers, and ranked destination landing pages for any account:
Post comments
Fetch public comments from Instagram posts/reels (by shortcode or URL) and TikTok videos (by video ID or URL):
Indexing an Account
If Spyglass does not have a brand or creator yet, submit its website or social profile URL (POST /account/index is free) and poll until status is "ready":
Async Usage
Import AsyncSpyglass for non-blocking calls with asyncio:
Error Handling
When the API returns a non-2xx status code, the SDK raises an ApiError containing the HTTP status code and parsed error body:
Retries, Timeouts & Raw Responses
Requests default to a 60-second timeout and 2 automatic retries with exponential backoff on 408, 429, and 5xx responses. Override these on the client or per request:
Access HTTP headers and status codes via .with_raw_response: