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, 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(
        brand_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)

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.0020 / brand returned 120 / min
client.search_creators(...) POST /creators $0.0020 / creator returned 120 / min
client.search_media(...) POST /media $0.0010 / creative returned 120 / min
client.search_taxonomies(query=...) GET /taxonomies Free 120 / min
client.get_comments(...) POST /comments $0.0100 / live page fetched 20 / min
client.account.get(id=...) GET /account/{id} $0.0020 / account returned 120 / min
client.account.insights(...) GET /account/{id}/insights $0.0010 / cluster returned 120 / min
client.account.landing_pages(...) GET /account/{id}/landing-pages $0.0050 / landing page 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.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)

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

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.5
File Size Uploaded
spyglass_sdk-0.1.5.tar.gz 67.0 kB Details

Built distribution (wheel)

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

Total release size: 173.4 kB

Release files / spyglass_sdk-0.1.5.tar.gz

Download URL spyglass_sdk-0.1.5.tar.gz
Size 67.0 kB
Tags Source
SHA-256 checksum
How to use checksums
6ddb21609938b6a4e69f30e10d47a0c831f50798fdf20a1c233e582a28eb2535
BLAKE2b-256 checksum
How to use checksums
a533c5a0e138549ca26331fe1f703cd29b331b0d4788ac6b388f1c979be17720
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 18, 2026.

Transparency log

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

Download URL spyglass_sdk-0.1.5-py3-none-any.whl
Size 106.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9224a323e288e34bedd9c1628fa25c11557718d6bb91fca0ea38ac9d6e5daa62
BLAKE2b-256 checksum
How to use checksums
3873ee3c184edd57283a9ec3e0f819526f39e0b43a28988c49389a6e36d92112
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Oct 18, 2026.

Transparency log

Release history Release notifications | RSS feed

0.1.6

2 release files

This release

0.1.5 This release

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

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