spyglass-sdk 0.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- spyglass_sdk-0.1.2/LICENSE +21 -0
- spyglass_sdk-0.1.2/PKG-INFO +231 -0
- spyglass_sdk-0.1.2/README.md +199 -0
- spyglass_sdk-0.1.2/pyproject.toml +96 -0
- spyglass_sdk-0.1.2/src/spyglass/__init__.py +286 -0
- spyglass_sdk-0.1.2/src/spyglass/_default_clients.py +32 -0
- spyglass_sdk-0.1.2/src/spyglass/account/__init__.py +34 -0
- spyglass_sdk-0.1.2/src/spyglass/account/client.py +114 -0
- spyglass_sdk-0.1.2/src/spyglass/account/raw_client.py +277 -0
- spyglass_sdk-0.1.2/src/spyglass/account/types/__init__.py +34 -0
- spyglass_sdk-0.1.2/src/spyglass/account/types/get_credit_usage_response.py +57 -0
- spyglass_sdk-0.1.2/src/spyglass/client.py +271 -0
- spyglass_sdk-0.1.2/src/spyglass/core/__init__.py +127 -0
- spyglass_sdk-0.1.2/src/spyglass/core/api_error.py +23 -0
- spyglass_sdk-0.1.2/src/spyglass/core/client_wrapper.py +148 -0
- spyglass_sdk-0.1.2/src/spyglass/core/datetime_utils.py +70 -0
- spyglass_sdk-0.1.2/src/spyglass/core/file.py +67 -0
- spyglass_sdk-0.1.2/src/spyglass/core/force_multipart.py +18 -0
- spyglass_sdk-0.1.2/src/spyglass/core/http_client.py +975 -0
- spyglass_sdk-0.1.2/src/spyglass/core/http_response.py +63 -0
- spyglass_sdk-0.1.2/src/spyglass/core/http_sse/__init__.py +42 -0
- spyglass_sdk-0.1.2/src/spyglass/core/http_sse/_api.py +455 -0
- spyglass_sdk-0.1.2/src/spyglass/core/http_sse/_decoders.py +74 -0
- spyglass_sdk-0.1.2/src/spyglass/core/http_sse/_exceptions.py +7 -0
- spyglass_sdk-0.1.2/src/spyglass/core/http_sse/_models.py +17 -0
- spyglass_sdk-0.1.2/src/spyglass/core/jsonable_encoder.py +133 -0
- spyglass_sdk-0.1.2/src/spyglass/core/logging.py +107 -0
- spyglass_sdk-0.1.2/src/spyglass/core/parse_error.py +36 -0
- spyglass_sdk-0.1.2/src/spyglass/core/pydantic_utilities.py +540 -0
- spyglass_sdk-0.1.2/src/spyglass/core/query_encoder.py +58 -0
- spyglass_sdk-0.1.2/src/spyglass/core/remove_none_from_dict.py +11 -0
- spyglass_sdk-0.1.2/src/spyglass/core/request_options.py +43 -0
- spyglass_sdk-0.1.2/src/spyglass/core/serialization.py +347 -0
- spyglass_sdk-0.1.2/src/spyglass/environment.py +7 -0
- spyglass_sdk-0.1.2/src/spyglass/errors/__init__.py +62 -0
- spyglass_sdk-0.1.2/src/spyglass/errors/bad_request_error.py +11 -0
- spyglass_sdk-0.1.2/src/spyglass/errors/content_too_large_error.py +11 -0
- spyglass_sdk-0.1.2/src/spyglass/errors/forbidden_error.py +11 -0
- spyglass_sdk-0.1.2/src/spyglass/errors/internal_server_error.py +11 -0
- spyglass_sdk-0.1.2/src/spyglass/errors/method_not_allowed_error.py +11 -0
- spyglass_sdk-0.1.2/src/spyglass/errors/not_found_error.py +11 -0
- spyglass_sdk-0.1.2/src/spyglass/errors/payment_required_error.py +11 -0
- spyglass_sdk-0.1.2/src/spyglass/errors/too_many_requests_error.py +11 -0
- spyglass_sdk-0.1.2/src/spyglass/errors/unauthorized_error.py +11 -0
- spyglass_sdk-0.1.2/src/spyglass/indexing/__init__.py +49 -0
- spyglass_sdk-0.1.2/src/spyglass/indexing/client.py +214 -0
- spyglass_sdk-0.1.2/src/spyglass/indexing/raw_client.py +553 -0
- spyglass_sdk-0.1.2/src/spyglass/indexing/types/__init__.py +47 -0
- spyglass_sdk-0.1.2/src/spyglass/indexing/types/index_brand_response.py +23 -0
- spyglass_sdk-0.1.2/src/spyglass/indexing/types/index_brand_response_status.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/indexing/types/index_brand_status_response.py +20 -0
- spyglass_sdk-0.1.2/src/spyglass/indexing/types/index_brand_status_response_status.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/py.typed +0 -0
- spyglass_sdk-0.1.2/src/spyglass/search/__init__.py +208 -0
- spyglass_sdk-0.1.2/src/spyglass/search/client.py +1429 -0
- spyglass_sdk-0.1.2/src/spyglass/search/raw_client.py +2984 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/__init__.py +206 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_account_response.py +110 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_account_response_brand.py +52 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_account_response_creator.py +57 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_landing_pages_request_show_inactive.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_landing_pages_response.py +27 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_landing_pages_response_landing_pages_item.py +20 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_media_insights_request_type.py +7 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_media_insights_response.py +8 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_media_insights_response_buckets.py +25 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_media_insights_response_buckets_buckets_item.py +24 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_media_insights_response_buckets_buckets_item_clusters_item.py +26 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_media_insights_response_buckets_totals_item.py +22 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_media_insights_response_buckets_type.py +7 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_media_insights_response_rows.py +23 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_media_insights_response_rows_rows_item.py +20 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_brand_media_insights_response_rows_type.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_comments_response.py +21 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_comments_response_posts_item.py +27 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_comments_response_posts_item_comments_item.py +39 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_request_brand_id.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_request_categories_item.py +36 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_request_channel_item.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_request_date_preset.py +23 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_request_duration_item.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_request_format_item.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_request_funnel_stage_item.py +7 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_request_landing_page_match.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_request_language_item.py +160 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_request_sort_by.py +18 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_request_status.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_response.py +21 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_response_media_item.py +94 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_response_media_item_brand.py +46 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_response_media_item_brand_type.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_response_media_item_media_type.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_response_media_item_type.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_response_media_item_ugc_character.py +31 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_response_media_item_ugc_character_age_range.py +7 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_response_media_item_ugc_character_ethnicity.py +8 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/get_media_response_media_item_ugc_character_gender.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_brands_request_brand_ids_item.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_brands_request_sort_by.py +8 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_brands_response.py +26 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_brands_response_brands_item.py +54 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_brands_response_brands_item_type.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_creators_request_age_range.py +7 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_creators_request_brand_ids_item.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_creators_request_ethnicity.py +8 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_creators_request_gender.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_creators_request_language.py +160 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_creators_request_sort_by.py +8 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_creators_response.py +26 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_creators_response_creators_item.py +59 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_creators_response_creators_item_type.py +5 -0
- spyglass_sdk-0.1.2/src/spyglass/search/types/search_taxonomies_response.py +20 -0
- spyglass_sdk-0.1.2/src/spyglass/types/__init__.py +42 -0
- spyglass_sdk-0.1.2/src/spyglass/types/error.py +20 -0
- spyglass_sdk-0.1.2/src/spyglass/types/error_error.py +23 -0
- spyglass_sdk-0.1.2/src/spyglass/types/error_error_code.py +20 -0
- spyglass_sdk-0.1.2/src/spyglass/types/error_error_details_item.py +20 -0
- spyglass_sdk-0.1.2/src/spyglass/version.py +3 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Spyglass
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: spyglass-sdk
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary:
|
|
5
|
+
Requires-Python: >=3.10,<4.0
|
|
6
|
+
Classifier: Intended Audience :: Developers
|
|
7
|
+
Classifier: Operating System :: MacOS
|
|
8
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Operating System :: POSIX
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Provides-Extra: aiohttp
|
|
23
|
+
Requires-Dist: aiohttp (>=3.14.1,<4) ; (python_version >= "3.10") and (extra == "aiohttp")
|
|
24
|
+
Requires-Dist: httpx (>=0.21.2)
|
|
25
|
+
Requires-Dist: httpx-aiohttp (>=0.1.8,<0.2.0) ; (python_version >= "3.10") and (extra == "aiohttp")
|
|
26
|
+
Requires-Dist: pydantic (>=1.9.2)
|
|
27
|
+
Requires-Dist: pydantic-core (>=2.18.2,<3.0.0)
|
|
28
|
+
Requires-Dist: typing_extensions (>=4.0.0)
|
|
29
|
+
Project-URL: Repository, https://github.com/spyglass-so/spyglass-python
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
<div align="center">
|
|
33
|
+
<img src="https://raw.githubusercontent.com/spyglass-so/spyglass-python/main/assets/wordmark.svg" alt="Spyglass" width="360">
|
|
34
|
+
|
|
35
|
+
<h3>The API layer for the social internet</h3>
|
|
36
|
+
<p>Official Python SDK for the Spyglass API — search brands, creators, and the ads they run.</p>
|
|
37
|
+
|
|
38
|
+
<a href="https://app.spyglass.so">
|
|
39
|
+
<img src="https://img.shields.io/badge/Get_Started-111111?style=for-the-badge" alt="Get Started">
|
|
40
|
+
</a>
|
|
41
|
+
<a href="https://docs.spyglass.so">
|
|
42
|
+
<img src="https://img.shields.io/badge/Documentation-4A4A4A?style=for-the-badge" alt="Documentation">
|
|
43
|
+
</a>
|
|
44
|
+
<a href="https://spyglass.so">
|
|
45
|
+
<img src="https://img.shields.io/badge/spyglass.so-0A0A0A?style=for-the-badge" alt="spyglass.so">
|
|
46
|
+
</a>
|
|
47
|
+
</div>
|
|
48
|
+
|
|
49
|
+
<br>
|
|
50
|
+
|
|
51
|
+
<div align="center">
|
|
52
|
+
<a href="https://github.com/spyglass-so/spyglass-python/blob/main/LICENSE">
|
|
53
|
+
<img src="https://img.shields.io/github/license/spyglass-so/spyglass-python" alt="License">
|
|
54
|
+
</a>
|
|
55
|
+
<a href="https://github.com/spyglass-so/spyglass-python/stargazers">
|
|
56
|
+
<img src="https://img.shields.io/github/stars/spyglass-so/spyglass-python?style=social" alt="Stars">
|
|
57
|
+
</a>
|
|
58
|
+
<a href="https://pypi.org/project/spyglass-sdk/">
|
|
59
|
+
<img src="https://img.shields.io/pypi/v/spyglass-sdk" alt="PyPI">
|
|
60
|
+
</a>
|
|
61
|
+
<a href="https://github.com/spyglass-so/spyglass-typescript">
|
|
62
|
+
<img src="https://img.shields.io/badge/TypeScript_SDK-%40spyglasshq%2Fsdk-3178C6?logo=typescript&logoColor=white" alt="TypeScript SDK">
|
|
63
|
+
</a>
|
|
64
|
+
</div>
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
**`spyglass-sdk`** is the official Python client for the [Spyglass API](https://docs.spyglass.so) 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.
|
|
69
|
+
|
|
70
|
+
> Looking for TypeScript / Node.js? See [`spyglass-so/spyglass-typescript`](https://github.com/spyglass-so/spyglass-typescript) (`npm install @spyglasshq/sdk`).
|
|
71
|
+
|
|
72
|
+
## Installation
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
pip install spyglass-sdk
|
|
76
|
+
# or
|
|
77
|
+
uv add spyglass-sdk
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Quickstart
|
|
81
|
+
|
|
82
|
+
Create an API key in **[Settings → API](https://app.spyglass.so)**. Keys start with `sg_live_` and are shown once.
|
|
83
|
+
|
|
84
|
+
```python
|
|
85
|
+
import os
|
|
86
|
+
from spyglass import Spyglass
|
|
87
|
+
|
|
88
|
+
client = Spyglass(token=os.environ["SPYGLASS_API_KEY"])
|
|
89
|
+
|
|
90
|
+
# 1. Resolve a brand
|
|
91
|
+
result = client.search.brands(names=["Nike"], limit=1)
|
|
92
|
+
|
|
93
|
+
if result.brands:
|
|
94
|
+
brand = result.brands[0]
|
|
95
|
+
|
|
96
|
+
# 2. Search the creatives that brand is running
|
|
97
|
+
media_result = client.search.get_media(
|
|
98
|
+
brand_id=brand.id,
|
|
99
|
+
query="marathon running shoes comfort",
|
|
100
|
+
limit=10,
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
for ad in media_result.media:
|
|
104
|
+
print(ad.id, ad.hook, ad.core_angle, ad.url)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Async Usage
|
|
108
|
+
|
|
109
|
+
Use `AsyncSpyglass` for non-blocking calls with `asyncio`:
|
|
110
|
+
|
|
111
|
+
```python
|
|
112
|
+
import asyncio
|
|
113
|
+
import os
|
|
114
|
+
from spyglass import AsyncSpyglass
|
|
115
|
+
|
|
116
|
+
client = AsyncSpyglass(token=os.environ["SPYGLASS_API_KEY"])
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
async def main() -> None:
|
|
120
|
+
result = await client.search.brands(names=["Nike"], limit=3)
|
|
121
|
+
for brand in result.brands:
|
|
122
|
+
print(brand.id, brand.name)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
asyncio.run(main())
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## API Reference Overview
|
|
129
|
+
|
|
130
|
+
| SDK Method | HTTP Endpoint | Cost | Rate Limit |
|
|
131
|
+
| --- | --- | --- | --- |
|
|
132
|
+
| `client.search.brands(...)` | `POST /brands` | $0.0020 / brand returned | 120 / min |
|
|
133
|
+
| `client.search.creators(...)` | `POST /creators` | $0.0020 / creator returned | 120 / min |
|
|
134
|
+
| `client.search.get_account(id=...)` | `GET /account/{id}` | $0.0020 / account returned | 120 / min |
|
|
135
|
+
| `client.search.get_media(...)` | `POST /media` | $0.0010 / creative returned | 120 / min |
|
|
136
|
+
| `client.search.taxonomies(query=...)` | `GET /taxonomies` | Free | 120 / min |
|
|
137
|
+
| `client.search.get_brand_media_insights(...)` | `GET /account/{id}/insights` | $0.0010 / cluster returned | 120 / min |
|
|
138
|
+
| `client.search.get_brand_landing_pages(...)` | `GET /account/{id}/landing-pages` | $0.0050 / landing page returned | 120 / min |
|
|
139
|
+
| `client.search.get_comments(...)` | `POST /comments` | $0.0100 / live page fetched | 20 / min |
|
|
140
|
+
| `client.indexing.index_brand(...)` | `POST /account/index` | Free | 50 / min |
|
|
141
|
+
| `client.indexing.index_brand_status(id=...)` | `GET /account/{id}/index-status` | Free | 300 / min |
|
|
142
|
+
| `client.account.get_credit_usage()` | `GET /team/credit-usage` | Free | 120 / min |
|
|
143
|
+
|
|
144
|
+
Full parameters and response schemas are documented in [`reference.md`](https://github.com/spyglass-so/spyglass-python/blob/main/reference.md) and at [docs.spyglass.so](https://docs.spyglass.so).
|
|
145
|
+
|
|
146
|
+
## Indexing a New Brand
|
|
147
|
+
|
|
148
|
+
If Spyglass doesn't have a brand yet, queue it by website or social profile URL (`POST /account/index` is free) and poll until `status` is `"ready"`:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
import time
|
|
152
|
+
|
|
153
|
+
indexed = client.indexing.index_brand(website_url="https://www.on.com")
|
|
154
|
+
|
|
155
|
+
status = indexed.status
|
|
156
|
+
while status == "indexing":
|
|
157
|
+
time.sleep(3)
|
|
158
|
+
check = client.indexing.index_brand_status(id=indexed.brand_id)
|
|
159
|
+
status = check.status
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## Error Handling
|
|
163
|
+
|
|
164
|
+
Non-2xx responses raise an `ApiError` with status code and parsed error body:
|
|
165
|
+
|
|
166
|
+
```python
|
|
167
|
+
from spyglass.core.api_error import ApiError
|
|
168
|
+
|
|
169
|
+
try:
|
|
170
|
+
client.search.brands(names=["Nike"], limit=5)
|
|
171
|
+
except ApiError as e:
|
|
172
|
+
print(e.status_code, e.body)
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Advanced Options
|
|
176
|
+
|
|
177
|
+
### Retries & Timeouts
|
|
178
|
+
|
|
179
|
+
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:
|
|
180
|
+
|
|
181
|
+
```python
|
|
182
|
+
client = Spyglass(token="...", timeout=30.0, max_retries=3)
|
|
183
|
+
|
|
184
|
+
response = client.search.brands(
|
|
185
|
+
names=["Nike"],
|
|
186
|
+
limit=5,
|
|
187
|
+
request_options={"timeout_in_seconds": 15, "max_retries": 1},
|
|
188
|
+
)
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
### Raw Response & Headers
|
|
192
|
+
|
|
193
|
+
Use `.with_raw_response` to inspect HTTP headers and status codes:
|
|
194
|
+
|
|
195
|
+
```python
|
|
196
|
+
raw = client.search.with_raw_response.brands(names=["Nike"], limit=1)
|
|
197
|
+
print(raw.status_code)
|
|
198
|
+
print(raw.headers)
|
|
199
|
+
print(raw.data.brands)
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
### Custom HTTPX Client
|
|
203
|
+
|
|
204
|
+
Pass a custom `httpx.Client` or `httpx.AsyncClient` for custom proxies or transport settings:
|
|
205
|
+
|
|
206
|
+
```python
|
|
207
|
+
import httpx
|
|
208
|
+
from spyglass import Spyglass
|
|
209
|
+
|
|
210
|
+
client = Spyglass(
|
|
211
|
+
token="...",
|
|
212
|
+
httpx_client=httpx.Client(proxy="http://proxy.example.com"),
|
|
213
|
+
)
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Billing & Conventions
|
|
217
|
+
|
|
218
|
+
- **Credits:** Most calls spend monthly credits per row returned (`count` in the response). Always bound requests with `limit`. See [Billing docs](https://docs.spyglass.so/documentation/get-started/billing).
|
|
219
|
+
- **Pagination:** Page through results with `offset` and `limit`. `count` is the number of rows in the current response.
|
|
220
|
+
- **Server-to-server:** Call the API from your backend, data pipeline, or agent runtime.
|
|
221
|
+
|
|
222
|
+
## Support
|
|
223
|
+
|
|
224
|
+
- **Documentation:** [docs.spyglass.so](https://docs.spyglass.so)
|
|
225
|
+
- **Issues:** [github.com/spyglass-so/spyglass-python/issues](https://github.com/spyglass-so/spyglass-python/issues)
|
|
226
|
+
- **Email:** [support@spyglass.so](mailto:support@spyglass.so)
|
|
227
|
+
|
|
228
|
+
## License
|
|
229
|
+
|
|
230
|
+
[MIT](https://github.com/spyglass-so/spyglass-python/blob/main/LICENSE)
|
|
231
|
+
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://raw.githubusercontent.com/spyglass-so/spyglass-python/main/assets/wordmark.svg" alt="Spyglass" width="360">
|
|
3
|
+
|
|
4
|
+
<h3>The API layer for the social internet</h3>
|
|
5
|
+
<p>Official Python SDK for the Spyglass API — search brands, creators, and the ads they run.</p>
|
|
6
|
+
|
|
7
|
+
<a href="https://app.spyglass.so">
|
|
8
|
+
<img src="https://img.shields.io/badge/Get_Started-111111?style=for-the-badge" alt="Get Started">
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://docs.spyglass.so">
|
|
11
|
+
<img src="https://img.shields.io/badge/Documentation-4A4A4A?style=for-the-badge" alt="Documentation">
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://spyglass.so">
|
|
14
|
+
<img src="https://img.shields.io/badge/spyglass.so-0A0A0A?style=for-the-badge" alt="spyglass.so">
|
|
15
|
+
</a>
|
|
16
|
+
</div>
|
|
17
|
+
|
|
18
|
+
<br>
|
|
19
|
+
|
|
20
|
+
<div align="center">
|
|
21
|
+
<a href="https://github.com/spyglass-so/spyglass-python/blob/main/LICENSE">
|
|
22
|
+
<img src="https://img.shields.io/github/license/spyglass-so/spyglass-python" alt="License">
|
|
23
|
+
</a>
|
|
24
|
+
<a href="https://github.com/spyglass-so/spyglass-python/stargazers">
|
|
25
|
+
<img src="https://img.shields.io/github/stars/spyglass-so/spyglass-python?style=social" alt="Stars">
|
|
26
|
+
</a>
|
|
27
|
+
<a href="https://pypi.org/project/spyglass-sdk/">
|
|
28
|
+
<img src="https://img.shields.io/pypi/v/spyglass-sdk" alt="PyPI">
|
|
29
|
+
</a>
|
|
30
|
+
<a href="https://github.com/spyglass-so/spyglass-typescript">
|
|
31
|
+
<img src="https://img.shields.io/badge/TypeScript_SDK-%40spyglasshq%2Fsdk-3178C6?logo=typescript&logoColor=white" alt="TypeScript SDK">
|
|
32
|
+
</a>
|
|
33
|
+
</div>
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
**`spyglass-sdk`** is the official Python client for the [Spyglass API](https://docs.spyglass.so) 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.
|
|
38
|
+
|
|
39
|
+
> Looking for TypeScript / Node.js? See [`spyglass-so/spyglass-typescript`](https://github.com/spyglass-so/spyglass-typescript) (`npm install @spyglasshq/sdk`).
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install spyglass-sdk
|
|
45
|
+
# or
|
|
46
|
+
uv add spyglass-sdk
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
## Quickstart
|
|
50
|
+
|
|
51
|
+
Create an API key in **[Settings → API](https://app.spyglass.so)**. Keys start with `sg_live_` and are shown once.
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
import os
|
|
55
|
+
from spyglass import Spyglass
|
|
56
|
+
|
|
57
|
+
client = Spyglass(token=os.environ["SPYGLASS_API_KEY"])
|
|
58
|
+
|
|
59
|
+
# 1. Resolve a brand
|
|
60
|
+
result = client.search.brands(names=["Nike"], limit=1)
|
|
61
|
+
|
|
62
|
+
if result.brands:
|
|
63
|
+
brand = result.brands[0]
|
|
64
|
+
|
|
65
|
+
# 2. Search the creatives that brand is running
|
|
66
|
+
media_result = client.search.get_media(
|
|
67
|
+
brand_id=brand.id,
|
|
68
|
+
query="marathon running shoes comfort",
|
|
69
|
+
limit=10,
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
for ad in media_result.media:
|
|
73
|
+
print(ad.id, ad.hook, ad.core_angle, ad.url)
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## Async Usage
|
|
77
|
+
|
|
78
|
+
Use `AsyncSpyglass` for non-blocking calls with `asyncio`:
|
|
79
|
+
|
|
80
|
+
```python
|
|
81
|
+
import asyncio
|
|
82
|
+
import os
|
|
83
|
+
from spyglass import AsyncSpyglass
|
|
84
|
+
|
|
85
|
+
client = AsyncSpyglass(token=os.environ["SPYGLASS_API_KEY"])
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
async def main() -> None:
|
|
89
|
+
result = await client.search.brands(names=["Nike"], limit=3)
|
|
90
|
+
for brand in result.brands:
|
|
91
|
+
print(brand.id, brand.name)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
asyncio.run(main())
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## API Reference Overview
|
|
98
|
+
|
|
99
|
+
| SDK Method | HTTP Endpoint | Cost | Rate Limit |
|
|
100
|
+
| --- | --- | --- | --- |
|
|
101
|
+
| `client.search.brands(...)` | `POST /brands` | $0.0020 / brand returned | 120 / min |
|
|
102
|
+
| `client.search.creators(...)` | `POST /creators` | $0.0020 / creator returned | 120 / min |
|
|
103
|
+
| `client.search.get_account(id=...)` | `GET /account/{id}` | $0.0020 / account returned | 120 / min |
|
|
104
|
+
| `client.search.get_media(...)` | `POST /media` | $0.0010 / creative returned | 120 / min |
|
|
105
|
+
| `client.search.taxonomies(query=...)` | `GET /taxonomies` | Free | 120 / min |
|
|
106
|
+
| `client.search.get_brand_media_insights(...)` | `GET /account/{id}/insights` | $0.0010 / cluster returned | 120 / min |
|
|
107
|
+
| `client.search.get_brand_landing_pages(...)` | `GET /account/{id}/landing-pages` | $0.0050 / landing page returned | 120 / min |
|
|
108
|
+
| `client.search.get_comments(...)` | `POST /comments` | $0.0100 / live page fetched | 20 / min |
|
|
109
|
+
| `client.indexing.index_brand(...)` | `POST /account/index` | Free | 50 / min |
|
|
110
|
+
| `client.indexing.index_brand_status(id=...)` | `GET /account/{id}/index-status` | Free | 300 / min |
|
|
111
|
+
| `client.account.get_credit_usage()` | `GET /team/credit-usage` | Free | 120 / min |
|
|
112
|
+
|
|
113
|
+
Full parameters and response schemas are documented in [`reference.md`](https://github.com/spyglass-so/spyglass-python/blob/main/reference.md) and at [docs.spyglass.so](https://docs.spyglass.so).
|
|
114
|
+
|
|
115
|
+
## Indexing a New Brand
|
|
116
|
+
|
|
117
|
+
If Spyglass doesn't have a brand yet, queue it by website or social profile URL (`POST /account/index` is free) and poll until `status` is `"ready"`:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
import time
|
|
121
|
+
|
|
122
|
+
indexed = client.indexing.index_brand(website_url="https://www.on.com")
|
|
123
|
+
|
|
124
|
+
status = indexed.status
|
|
125
|
+
while status == "indexing":
|
|
126
|
+
time.sleep(3)
|
|
127
|
+
check = client.indexing.index_brand_status(id=indexed.brand_id)
|
|
128
|
+
status = check.status
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Error Handling
|
|
132
|
+
|
|
133
|
+
Non-2xx responses raise an `ApiError` with status code and parsed error body:
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from spyglass.core.api_error import ApiError
|
|
137
|
+
|
|
138
|
+
try:
|
|
139
|
+
client.search.brands(names=["Nike"], limit=5)
|
|
140
|
+
except ApiError as e:
|
|
141
|
+
print(e.status_code, e.body)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
## Advanced Options
|
|
145
|
+
|
|
146
|
+
### Retries & Timeouts
|
|
147
|
+
|
|
148
|
+
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:
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
client = Spyglass(token="...", timeout=30.0, max_retries=3)
|
|
152
|
+
|
|
153
|
+
response = client.search.brands(
|
|
154
|
+
names=["Nike"],
|
|
155
|
+
limit=5,
|
|
156
|
+
request_options={"timeout_in_seconds": 15, "max_retries": 1},
|
|
157
|
+
)
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Raw Response & Headers
|
|
161
|
+
|
|
162
|
+
Use `.with_raw_response` to inspect HTTP headers and status codes:
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
raw = client.search.with_raw_response.brands(names=["Nike"], limit=1)
|
|
166
|
+
print(raw.status_code)
|
|
167
|
+
print(raw.headers)
|
|
168
|
+
print(raw.data.brands)
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Custom HTTPX Client
|
|
172
|
+
|
|
173
|
+
Pass a custom `httpx.Client` or `httpx.AsyncClient` for custom proxies or transport settings:
|
|
174
|
+
|
|
175
|
+
```python
|
|
176
|
+
import httpx
|
|
177
|
+
from spyglass import Spyglass
|
|
178
|
+
|
|
179
|
+
client = Spyglass(
|
|
180
|
+
token="...",
|
|
181
|
+
httpx_client=httpx.Client(proxy="http://proxy.example.com"),
|
|
182
|
+
)
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
## Billing & Conventions
|
|
186
|
+
|
|
187
|
+
- **Credits:** Most calls spend monthly credits per row returned (`count` in the response). Always bound requests with `limit`. See [Billing docs](https://docs.spyglass.so/documentation/get-started/billing).
|
|
188
|
+
- **Pagination:** Page through results with `offset` and `limit`. `count` is the number of rows in the current response.
|
|
189
|
+
- **Server-to-server:** Call the API from your backend, data pipeline, or agent runtime.
|
|
190
|
+
|
|
191
|
+
## Support
|
|
192
|
+
|
|
193
|
+
- **Documentation:** [docs.spyglass.so](https://docs.spyglass.so)
|
|
194
|
+
- **Issues:** [github.com/spyglass-so/spyglass-python/issues](https://github.com/spyglass-so/spyglass-python/issues)
|
|
195
|
+
- **Email:** [support@spyglass.so](mailto:support@spyglass.so)
|
|
196
|
+
|
|
197
|
+
## License
|
|
198
|
+
|
|
199
|
+
[MIT](https://github.com/spyglass-so/spyglass-python/blob/main/LICENSE)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "spyglass-sdk"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
|
|
5
|
+
[tool.poetry]
|
|
6
|
+
name = "spyglass-sdk"
|
|
7
|
+
version = "0.1.2"
|
|
8
|
+
description = ""
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = []
|
|
11
|
+
keywords = []
|
|
12
|
+
classifiers = [
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"Programming Language :: Python",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.10",
|
|
17
|
+
"Programming Language :: Python :: 3.11",
|
|
18
|
+
"Programming Language :: Python :: 3.12",
|
|
19
|
+
"Programming Language :: Python :: 3.13",
|
|
20
|
+
"Programming Language :: Python :: 3.14",
|
|
21
|
+
"Programming Language :: Python :: 3.15",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Operating System :: POSIX",
|
|
24
|
+
"Operating System :: MacOS",
|
|
25
|
+
"Operating System :: POSIX :: Linux",
|
|
26
|
+
"Operating System :: Microsoft :: Windows",
|
|
27
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
28
|
+
"Typing :: Typed"
|
|
29
|
+
]
|
|
30
|
+
packages = [
|
|
31
|
+
{ include = "spyglass", from = "src"}
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[tool.poetry.urls]
|
|
35
|
+
Repository = 'https://github.com/spyglass-so/spyglass-python'
|
|
36
|
+
|
|
37
|
+
[tool.poetry.dependencies]
|
|
38
|
+
python = "^3.10"
|
|
39
|
+
aiohttp = { version = ">=3.14.1,<4", optional = true, python = ">=3.10"}
|
|
40
|
+
httpx = ">=0.21.2"
|
|
41
|
+
httpx-aiohttp = { version = "^0.1.8", optional = true, python = ">=3.10"}
|
|
42
|
+
pydantic = ">= 1.9.2"
|
|
43
|
+
pydantic-core = ">=2.18.2,<3.0.0"
|
|
44
|
+
typing_extensions = ">= 4.0.0"
|
|
45
|
+
|
|
46
|
+
[tool.poetry.group.dev.dependencies]
|
|
47
|
+
mypy = "==1.13.0"
|
|
48
|
+
pytest = "^9.0.3"
|
|
49
|
+
pytest-asyncio = "^1.0.0"
|
|
50
|
+
pytest-xdist = "^3.6.1"
|
|
51
|
+
python-dateutil = "^2.9.0"
|
|
52
|
+
types-python-dateutil = "^2.9.0.20240316"
|
|
53
|
+
urllib3 = ">=2.6.3,<3.0.0"
|
|
54
|
+
ruff = "==0.11.5"
|
|
55
|
+
|
|
56
|
+
[tool.pytest.ini_options]
|
|
57
|
+
testpaths = [ "tests" ]
|
|
58
|
+
asyncio_mode = "auto"
|
|
59
|
+
norecursedirs = [ "src" ]
|
|
60
|
+
markers = [
|
|
61
|
+
"aiohttp: tests that require httpx_aiohttp to be installed",
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[tool.mypy]
|
|
65
|
+
plugins = ["pydantic.mypy"]
|
|
66
|
+
|
|
67
|
+
[tool.ruff]
|
|
68
|
+
line-length = 120
|
|
69
|
+
|
|
70
|
+
[tool.ruff.lint]
|
|
71
|
+
select = [
|
|
72
|
+
"E", # pycodestyle errors
|
|
73
|
+
"F", # pyflakes
|
|
74
|
+
"I", # isort
|
|
75
|
+
]
|
|
76
|
+
ignore = [
|
|
77
|
+
"E402", # Module level import not at top of file
|
|
78
|
+
"E501", # Line too long
|
|
79
|
+
"E711", # Comparison to `None` should be `cond is not None`
|
|
80
|
+
"E712", # Avoid equality comparisons to `True`; use `if ...:` checks
|
|
81
|
+
"E721", # Use `is` and `is not` for type comparisons, or `isinstance()` for insinstance checks
|
|
82
|
+
"E722", # Do not use bare `except`
|
|
83
|
+
"E731", # Do not assign a `lambda` expression, use a `def`
|
|
84
|
+
"F821", # Undefined name
|
|
85
|
+
"F841" # Local variable ... is assigned to but never used
|
|
86
|
+
]
|
|
87
|
+
|
|
88
|
+
[tool.ruff.lint.isort]
|
|
89
|
+
section-order = ["future", "standard-library", "third-party", "first-party"]
|
|
90
|
+
|
|
91
|
+
[build-system]
|
|
92
|
+
requires = ["poetry-core"]
|
|
93
|
+
build-backend = "poetry.core.masonry.api"
|
|
94
|
+
|
|
95
|
+
[tool.poetry.extras]
|
|
96
|
+
aiohttp=["aiohttp", "httpx-aiohttp"]
|