The API layer for the social internet
Official Python SDK for the Spyglass API — search brands, creators, and the ads they run.
spyglass-sdk is the official Python client for the Spyglass API with both synchronous (Spyglass) and asynchronous (AsyncSpyglass) clients. Resolve brands and creators, search across millions of Meta, Instagram, and TikTok creatives with natural-language briefs or structured filters, and extract hooks, personas, campaigns, collaborations, landing pages, and public comments.
Looking for TypeScript / Node.js? See
spyglass-so/spyglass-typescript(npm install @spyglasshq/sdk).
Installation
pip install spyglass-sdk
# or
uv add spyglass-sdk
Quickstart
Create an API key in Settings → API. Keys start with sg_live_ and are shown once.
import os
from spyglass import Spyglass
client = Spyglass(token=os.environ["SPYGLASS_API_KEY"])
# 1. Resolve a brand
result = client.search_brands(names=["Nike"], limit=1)
if result.brands:
brand = result.brands[0]
# 2. Search the creatives that brand is running
media_result = client.search_media(
account_id=brand.id,
query="marathon running shoes comfort",
limit=10,
)
for ad in media_result.media:
print(ad.id, ad.hook, ad.core_angle, ad.url)
Creative Insights, Campaigns, Collabs & Landing Pages
Pull clustered creative themes (HOOK, USP, PERSONA, MEDIA_MIX), campaigns or offers, creator collaborations, and ranked destination landing pages for any account:
# Ranked hooks + weekly volume breakdown over the last 90 days
insights = client.account.insights(
id=brand.id,
type="HOOK",
max_days_back=90,
limit=10,
)
# Active campaigns or promotional offers
campaigns = client.account.campaigns(
id=brand.id,
type="CAMPAIGN",
date_preset="last-30-days",
limit=10,
)
# Creators the account has collaborated with, ordered by media count
collabs = client.account.collabs(
id=brand.id,
limit=20,
)
# Top landing pages where the brand sends ad traffic
landing_pages = client.account.landing_pages(
id=brand.id,
show_inactive="false",
limit=20,
)
Account posts
Fetch an account's posts live with GET /account/posts. The account does not need to be indexed. Send exactly one of ig_username, tiktok_username, or facebook_ad_library_id. The call usually takes 10–30 seconds and can run up to 5 minutes, so raise the timeout above the 60-second default.
posts = client.account.posts(
ig_username="nike",
post_type="reels",
limit=20,
request_options={"timeout_in_seconds": 300},
)
# TikTok, most recent by default. sort_by can be "popular".
client.account.posts(
tiktok_username="nike",
sort_by="most_recent",
limit=20,
request_options={"timeout_in_seconds": 300},
)
# Facebook Ad Library. sort_by can be "most_impressions".
client.account.posts(
facebook_ad_library_id="15087023444",
limit=20,
request_options={"timeout_in_seconds": 300},
)
Async Usage
Use AsyncSpyglass for non-blocking calls with asyncio:
import asyncio
import os
from spyglass import AsyncSpyglass
client = AsyncSpyglass(token=os.environ["SPYGLASS_API_KEY"])
async def main() -> None:
result = await client.search_brands(names=["Nike"], limit=3)
for brand in result.brands:
print(brand.id, brand.name)
asyncio.run(main())
API Reference Overview
| SDK Method | HTTP Endpoint | Cost | Rate Limit |
|---|---|---|---|
client.search_brands(...) |
POST /brands |
$0.0010 / brand returned | 120 / min |
client.search_creators(...) |
POST /creators |
$0.0010 / creator returned | 120 / min |
client.search_media(...) |
POST /media |
$0.0005 / creative returned | 120 / min |
client.search_taxonomies(query=...) |
GET /taxonomies |
Free | 120 / min |
client.get_comments(...) |
POST /comments |
$0.0050 / live page fetched | 20 / min |
client.account.get(id=...) |
GET /account/{id} |
$0.0010 / account returned | 120 / min |
client.account.insights(...) |
GET /account/{id}/insights |
$0.0005 / cluster returned | 120 / min |
client.account.campaigns(...) |
GET /account/{id}/campaigns |
$0.0005 / campaign returned | 120 / min |
client.account.collabs(...) |
GET /account/{id}/collabs |
$0.0005 / collab returned | 120 / min |
client.account.landing_pages(...) |
GET /account/{id}/landing-pages |
$0.0025 / landing page returned | 120 / min |
client.account.posts(...) |
GET /account/posts |
$0.0010 / post returned | 120 / min |
client.account.index(...) |
POST /account/index |
Free | 50 / min |
client.account.index_status(id=...) |
GET /account/{id}/index-status |
Free | 300 / min |
client.agent.runs.create(...) |
POST /agent/runs |
Free to queue; billed from model usage when the run finishes | 20 / min |
client.agent.runs.list(...) |
GET /agent/runs |
Free | 120 / min |
client.agent.runs.get(id=...) |
GET /agent/runs/{id} |
Free | 120 / min |
client.get_credit_usage() |
GET /team/credit-usage |
Free | 120 / min |
Full parameters and response schemas are documented in reference.md and at docs.spyglass.so.
Indexing a New Account
If Spyglass doesn't have a brand or creator yet, queue it by website or social profile URL (POST /account/index is free) and poll until status is "ready":
import time
indexed = client.account.index(website_url="https://www.on.com")
status = indexed.status
while status == "indexing":
time.sleep(3)
check = client.account.index_status(id=indexed.brand_id)
status = check.status
if status in ("ready", "already_exists"):
account = client.account.get(id=indexed.brand_id)
print("Indexed account:", account.name)
Run the Agent
Start a Spyglass agent run, then poll until status is "completed". Queuing the run is free. The run is billed from model usage when it finishes. effort is none, minimal, low, medium (default), high, or xhigh.
Pass a JSON Schema output_schema (type "object") to also get structured on the completed run. Pass previous_run_id of a completed run to continue that thread. Page the list with offset. The next page is offset plus limit, and you stop when fewer than limit runs come back.
import time
created = client.agent.runs.create(
query="What are three hooks Liquid Death uses in recent ads?",
effort="low",
output_schema={
"type": "object",
"properties": {
"hooks": {"type": "array", "items": {"type": "string"}},
},
"required": ["hooks"],
},
)
run = client.agent.runs.get(id=created.id)
while run.status != "completed":
time.sleep(3)
run = client.agent.runs.get(id=created.id)
print(run.text)
print(run.structured)
# Continue the same thread
client.agent.runs.create(
query="Turn those hooks into 15-second ad scripts.",
previous_run_id=run.id,
)
page = client.agent.runs.list(limit=10, offset=0)
Error Handling
Non-2xx responses raise an ApiError with status code and parsed error body:
from spyglass.core.api_error import ApiError
try:
client.search_brands(names=["Nike"], limit=5)
except ApiError as e:
print(e.status_code, e.body)
Advanced Options
Retries & Timeouts
Requests default to a 60-second timeout and up to 2 automatic retries with exponential backoff on 408, 409, 429, and 5xx responses. Override at the client or per-request level:
client = Spyglass(token="...", timeout=30.0, max_retries=3)
response = client.search_brands(
names=["Nike"],
limit=5,
request_options={"timeout_in_seconds": 15, "max_retries": 1},
)
Raw Response & Headers
Use .with_raw_response to inspect HTTP headers and status codes:
raw = client.with_raw_response.search_brands(names=["Nike"], limit=1)
print(raw.status_code)
print(raw.headers)
print(raw.data.brands)
Custom HTTPX Client
Pass a custom httpx.Client or httpx.AsyncClient for custom proxies or transport settings:
import httpx
from spyglass import Spyglass
client = Spyglass(
token="...",
httpx_client=httpx.Client(proxy="http://proxy.example.com"),
)
Billing & Conventions
- Credits: Most calls spend monthly credits per row returned (
countin the response). Always bound requests withlimit. See Billing docs. - Pagination: Page through results with
offsetandlimit.countis the number of rows in the current response. - Server-to-server: Call the API from your backend, data pipeline, or agent runtime.
Support
- Documentation: docs.spyglass.so
- Issues: github.com/spyglass-so/spyglass-python/issues
- Email: support@spyglass.so
License
Metadata
Release files for spyglass-sdk 0.1.35
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spyglass_sdk-0.1.35.tar.gz | 88.1 kB | With provenance | Details for spyglass_sdk-0.1.35.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spyglass_sdk-0.1.35-py3-none-any.whl | Python 3 | none | any | Details for spyglass_sdk-0.1.35-py3-none-any.whl |
Total release size: 229.5 kB
Release files / spyglass_sdk-0.1.35.tar.gz
| Download URL | spyglass_sdk-0.1.35.tar.gz |
|---|---|
| Size | 88.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fe229ef3de49617cbf2b8259338e06b003ef8de6eff2aa3fa98c98e211dfcf81
|
|
BLAKE2b-256 checksum How to use checksums |
a90bb0b4f3c4d06f32c6a35c996d97a8cc1b2d2d1c23ce228e83f15cbeed9f93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logRelease files / spyglass_sdk-0.1.35-py3-none-any.whl
| Download URL | spyglass_sdk-0.1.35-py3-none-any.whl |
|---|---|
| Size | 141.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cdd508e2742e4291c2a1f4ffe4e087279b38cf41658ef28a5f154dfb6d148c8d
|
|
BLAKE2b-256 checksum How to use checksums |
147f3996e174924cb074978e212f750b4b0e66691a46aa82d66f5ac6e5c8b1e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logSecurity for spyglass-sdk 0.1.35
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for spyglass_sdk-0.1.35.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 21, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.