Skip to main content
Spyglass

The API layer for the social internet

Official Python SDK for the Spyglass API — search brands, creators, and the ads they run.

Get Started Documentation spyglass.so


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 (count in the response). Always bound requests with limit. See Billing docs.
  • Pagination: Page through results with offset and limit. count is the number of rows in the current response.
  • Server-to-server: Call the API from your backend, data pipeline, or agent runtime.

Support

License

MIT

Metadata

Release files for spyglass-sdk 0.1.33

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spyglass-sdk 0.1.33
File Size Uploaded Provenance Actions
spyglass_sdk-0.1.33.tar.gz 85.5 kB With provenance Details for spyglass_sdk-0.1.33.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spyglass-sdk 0.1.33
File Interpreter ABI Platform Actions
spyglass_sdk-0.1.33-py3-none-any.whl Python 3 none any Details for spyglass_sdk-0.1.33-py3-none-any.whl

Total release size: 223.1 kB

Release files / spyglass_sdk-0.1.33.tar.gz

Download URL spyglass_sdk-0.1.33.tar.gz
Size 85.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3a540f6f207a9a9bd7d962f10ac6cacb539276cda3977be23c9c7e6b7524cbb0
BLAKE2b-256 checksum
How to use checksums
212fbffed575b0180dc8634fd8f3e65dc770a7c434534d31b9b2895417f1478c
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 19, 2026.

Transparency log

Release files / spyglass_sdk-0.1.33-py3-none-any.whl

Download URL spyglass_sdk-0.1.33-py3-none-any.whl
Size 137.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
85dd45091130d5f12236925d51854397cd60b028156f58712bd6f035b57d44b3
BLAKE2b-256 checksum
How to use checksums
59fbc14248a842637d62c83f13e1e8982a733680c9106cae3e0897c33d34983d
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 19, 2026.

Transparency log

Security for spyglass-sdk 0.1.33

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.

Select from 2 files

Attestation for spyglass_sdk-0.1.33.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 19, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page