raspbytes 1.1.0__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.
- raspbytes-1.1.0/.gitignore +11 -0
- raspbytes-1.1.0/LICENSE +25 -0
- raspbytes-1.1.0/PKG-INFO +297 -0
- raspbytes-1.1.0/README.md +264 -0
- raspbytes-1.1.0/pyproject.toml +100 -0
- raspbytes-1.1.0/src/raspbytes/__init__.py +87 -0
- raspbytes-1.1.0/src/raspbytes/_core/__init__.py +1 -0
- raspbytes-1.1.0/src/raspbytes/_core/constants.py +38 -0
- raspbytes-1.1.0/src/raspbytes/_core/http.py +160 -0
- raspbytes-1.1.0/src/raspbytes/_core/transport.py +175 -0
- raspbytes-1.1.0/src/raspbytes/_core/types.py +11 -0
- raspbytes-1.1.0/src/raspbytes/_core/version.py +8 -0
- raspbytes-1.1.0/src/raspbytes/client.py +88 -0
- raspbytes-1.1.0/src/raspbytes/config.py +122 -0
- raspbytes-1.1.0/src/raspbytes/countries.py +278 -0
- raspbytes-1.1.0/src/raspbytes/exceptions.py +115 -0
- raspbytes-1.1.0/src/raspbytes/managed_scrapers.py +4 -0
- raspbytes-1.1.0/src/raspbytes/models.py +89 -0
- raspbytes-1.1.0/src/raspbytes/py.typed +1 -0
- raspbytes-1.1.0/src/raspbytes/resources/__init__.py +17 -0
- raspbytes-1.1.0/src/raspbytes/resources/_base.py +75 -0
- raspbytes-1.1.0/src/raspbytes/resources/_polling.py +73 -0
- raspbytes-1.1.0/src/raspbytes/resources/browser.py +185 -0
- raspbytes-1.1.0/src/raspbytes/resources/proxies.py +49 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/__init__.py +45 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/_generated/__init__.py +1 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/_generated/managed.py +190 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/_generated/wire.py +632 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/_managed.py +14 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/_request.py +128 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/builder.py +199 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/hub.py +168 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/monitoring.py +132 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/runs.py +202 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/schedules.py +172 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/storage.py +155 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/tasks.py +134 -0
- raspbytes-1.1.0/src/raspbytes/resources/scraper/types.py +96 -0
- raspbytes-1.1.0/src/raspbytes/resources/unblocker.py +131 -0
- raspbytes-1.1.0/src/raspbytes/scraper_types.py +4 -0
raspbytes-1.1.0/LICENSE
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
BSD 2-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Phoenix Point Limited
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
9
|
+
this list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
16
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
17
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
18
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
19
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
20
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
21
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
22
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
23
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
24
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
25
|
+
POSSIBILITY OF SUCH DAMAGE.
|
raspbytes-1.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: raspbytes
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Official Python SDK for the Raspbytes API
|
|
5
|
+
Project-URL: Documentation, https://docs.raspbytes.com/reference
|
|
6
|
+
Project-URL: Homepage, https://raspbytes.com
|
|
7
|
+
Project-URL: Issues, https://github.com/raspbytes-labs/python-sdk/issues
|
|
8
|
+
Project-URL: Repository, https://github.com/raspbytes-labs/python-sdk
|
|
9
|
+
Project-URL: Changelog, https://github.com/raspbytes-labs/python-sdk/blob/main/CHANGELOG.md
|
|
10
|
+
Author: Raspbytes
|
|
11
|
+
License-Expression: BSD-2-Clause
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Keywords: browser-api,proxy,raspbytes,scraping
|
|
14
|
+
Classifier: Development Status :: 3 - Alpha
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
22
|
+
Classifier: Typing :: Typed
|
|
23
|
+
Requires-Python: >=3.11
|
|
24
|
+
Requires-Dist: httpx<1,>=0.27
|
|
25
|
+
Provides-Extra: dev
|
|
26
|
+
Requires-Dist: mypy<2,>=1.13; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-asyncio<2,>=1.4.1; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest-cov<8,>=6; extra == 'dev'
|
|
29
|
+
Requires-Dist: pytest<9,>=8; extra == 'dev'
|
|
30
|
+
Requires-Dist: ruff<1,>=0.8; extra == 'dev'
|
|
31
|
+
Requires-Dist: twine<8,>=7; extra == 'dev'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# Raspbytes Python SDK
|
|
35
|
+
|
|
36
|
+
The official Python SDK for Raspbytes provides synchronous and asynchronous clients for
|
|
37
|
+
Proxies, Browser API, Web Unblocker, and Scraper API. It includes typed requests, structured
|
|
38
|
+
API errors, and helpers for polling long-running operations.
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
Requires Python 3.11 or later.
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
python -m pip install raspbytes
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Authentication
|
|
49
|
+
|
|
50
|
+
Create an API key in the Raspbytes dashboard and set `RASPBYTES_API_KEY` in your environment.
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
export RASPBYTES_API_KEY='rb_live_your_key_here'
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Both clients read `RASPBYTES_API_KEY` automatically. You can also pass `api_key=` when
|
|
57
|
+
creating a client.
|
|
58
|
+
|
|
59
|
+
## Quick start
|
|
60
|
+
|
|
61
|
+
Fetch a page with Web Unblocker. The client context manager closes the HTTP connection pool.
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from raspbytes import Raspbytes, UnblockRequest
|
|
65
|
+
|
|
66
|
+
with Raspbytes() as client:
|
|
67
|
+
page = client.unblocker.retrieve(UnblockRequest(url="https://example.com"))
|
|
68
|
+
|
|
69
|
+
print(page["status"], page["http_status"])
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Proxies
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
from raspbytes import ProxyConnectionParams, Raspbytes
|
|
76
|
+
|
|
77
|
+
with Raspbytes() as client:
|
|
78
|
+
connection = client.proxies.create(
|
|
79
|
+
ProxyConnectionParams(
|
|
80
|
+
proxy_type="residential",
|
|
81
|
+
country="US",
|
|
82
|
+
protocol="http",
|
|
83
|
+
)
|
|
84
|
+
)
|
|
85
|
+
proxy_url = connection["proxy_url"]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
Pass `proxy_url` directly to your HTTP client's proxy setting. The URL contains credentials.
|
|
89
|
+
Use `proxies.options()` to discover available locations and protocols for your account.
|
|
90
|
+
For a sticky connection, provide `session_type="sticky"` and a `session_id`. Use
|
|
91
|
+
`release_sticky_session(session_id)` to end the session early.
|
|
92
|
+
|
|
93
|
+
## Browser API
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
from raspbytes import BrowserProxy, BrowserSessionParams, Raspbytes
|
|
97
|
+
|
|
98
|
+
with Raspbytes() as client:
|
|
99
|
+
created = client.browser.create_session(
|
|
100
|
+
BrowserSessionParams(
|
|
101
|
+
browser="chromium",
|
|
102
|
+
proxy=BrowserProxy(type="datacenter", country="GB"),
|
|
103
|
+
session_timeout_seconds=900,
|
|
104
|
+
)
|
|
105
|
+
)
|
|
106
|
+
try:
|
|
107
|
+
session = client.browser.wait_until_ready(created["id"])
|
|
108
|
+
browser_url = session["connection"]["url"]
|
|
109
|
+
# Use browser_url with Playwright's chromium.connect_over_cdp().
|
|
110
|
+
finally:
|
|
111
|
+
client.browser.terminate_session(created["id"])
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Keep the browser WebSocket URL private. Use `browser.proxy_options()` to discover available
|
|
115
|
+
proxy options for your account.
|
|
116
|
+
|
|
117
|
+
## Web Unblocker
|
|
118
|
+
|
|
119
|
+
Use `retrieve()` to fetch a page in one request. To submit the request and collect the result
|
|
120
|
+
later, use `create_request()` and `wait_for_request()`.
|
|
121
|
+
|
|
122
|
+
```python
|
|
123
|
+
from raspbytes import Raspbytes, UnblockRequest
|
|
124
|
+
|
|
125
|
+
with Raspbytes() as client:
|
|
126
|
+
queued = client.unblocker.create_request(UnblockRequest(url="https://example.com"))
|
|
127
|
+
completed = client.unblocker.wait_for_request(queued["id"], timeout=120)
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Scraper API
|
|
131
|
+
|
|
132
|
+
Google, Bing, and DuckDuckGo are managed scrapers under `client.scraper`. The managed catalog
|
|
133
|
+
exports a typed input dictionary and a revision-pinned handle for each scraper.
|
|
134
|
+
|
|
135
|
+
```python
|
|
136
|
+
from uuid import uuid4
|
|
137
|
+
|
|
138
|
+
from raspbytes import Raspbytes
|
|
139
|
+
from raspbytes.managed_scrapers import GOOGLE_SEARCH, GoogleSearchInputs
|
|
140
|
+
|
|
141
|
+
with Raspbytes() as client:
|
|
142
|
+
scraper = client.scraper
|
|
143
|
+
inputs = GoogleSearchInputs(
|
|
144
|
+
query="coffee shops in London",
|
|
145
|
+
country="gb",
|
|
146
|
+
language="en",
|
|
147
|
+
device="desktop",
|
|
148
|
+
)
|
|
149
|
+
run = scraper.hub.run_managed(
|
|
150
|
+
GOOGLE_SEARCH,
|
|
151
|
+
inputs,
|
|
152
|
+
idempotency_key=str(uuid4()),
|
|
153
|
+
)
|
|
154
|
+
completed = scraper.runs.wait(run["id"], timeout=90)
|
|
155
|
+
print(completed.get("result"))
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
Use `hub.list()` and `hub.get()` to discover available scrapers, revisions, and input and
|
|
159
|
+
output schemas. For private or newly discovered scrapers, pass the Hub ID and inputs to
|
|
160
|
+
`hub.run()` or `hub.run_and_wait()`. Use the scraper's output schema to validate the `result`
|
|
161
|
+
field for your application.
|
|
162
|
+
|
|
163
|
+
Use `runs.iterate()` to stream run history across pages and `runs.cancel(run_id)` to cancel a
|
|
164
|
+
server-side run. Cancelling an asyncio task stops the local wait. An idempotency key enables
|
|
165
|
+
response retries for a submission when the service marks the failure retryable. Use a new key
|
|
166
|
+
for each logical run and reuse it when retrying that run.
|
|
167
|
+
|
|
168
|
+
`COUNTRIES` provides ISO country codes and display names. For managed search scrapers, the
|
|
169
|
+
`country` input selects the search market and `configuration.country` sets the execution origin.
|
|
170
|
+
|
|
171
|
+
### Manage Scraper workflows
|
|
172
|
+
|
|
173
|
+
Use `scraper.tasks` to save Hub inputs, create revisions, and run a saved task. Use
|
|
174
|
+
`scraper.schedules` to run a task on a cadence or submit an immediate run.
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
from raspbytes import Raspbytes
|
|
178
|
+
from raspbytes.managed_scrapers import GOOGLE_SEARCH
|
|
179
|
+
from raspbytes.scraper_types import CreateScrapingTaskParams
|
|
180
|
+
|
|
181
|
+
task_request = CreateScrapingTaskParams(
|
|
182
|
+
scraper=GOOGLE_SEARCH.id,
|
|
183
|
+
revision=GOOGLE_SEARCH.revision,
|
|
184
|
+
name="London coffee shops",
|
|
185
|
+
configuration={
|
|
186
|
+
"inputs": {
|
|
187
|
+
"query": "coffee shops in London",
|
|
188
|
+
"country": "gb",
|
|
189
|
+
"language": "en",
|
|
190
|
+
"device": "desktop",
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
with Raspbytes() as client:
|
|
196
|
+
task = client.scraper.tasks.create(task_request)
|
|
197
|
+
schedule = client.scraper.schedules.create(
|
|
198
|
+
{
|
|
199
|
+
"task": task["id"],
|
|
200
|
+
"name": "Weekday refresh",
|
|
201
|
+
"frequency": "custom",
|
|
202
|
+
"weekdays": [1, 2, 3, 4, 5],
|
|
203
|
+
"timezone": "Europe/London",
|
|
204
|
+
"time_of_day": "09:00:00",
|
|
205
|
+
}
|
|
206
|
+
)
|
|
207
|
+
run = client.scraper.schedules.run_now(schedule["id"])
|
|
208
|
+
finished = client.scraper.runs.wait(run["id"], timeout=90)
|
|
209
|
+
artifacts = client.scraper.storage.list_for_run(finished["id"])
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
- `storage.iterate()` streams retained outputs. `create_download_link()` returns a short-lived
|
|
213
|
+
URL that should be treated as a secret.
|
|
214
|
+
- `monitoring.get(scope_type="task", scope_id=task_id, window="24h")` reads task metrics.
|
|
215
|
+
`list_scopes()` discovers available scopes. Policy methods read, patch, or evaluate alerts.
|
|
216
|
+
- `builder` manages account-owned scrapers, immutable revisions, access shares, and publication.
|
|
217
|
+
- `schedules.pause()` and `schedules.resume()` set an explicit enabled state. Use
|
|
218
|
+
`toggle_pause()` when you want the API to flip the current state.
|
|
219
|
+
|
|
220
|
+
Request and response types are available from `raspbytes.scraper_types`. With
|
|
221
|
+
`AsyncRaspbytes`, await the same methods and use `async for` with `storage.iterate()`.
|
|
222
|
+
|
|
223
|
+
### Migrating from SERP
|
|
224
|
+
|
|
225
|
+
Replace `client.serp` with `client.scraper`. Choose `GOOGLE_SEARCH`, `BING_SEARCH`, or
|
|
226
|
+
`DUCKDUCKGO_SEARCH` in place of the old engine argument, and consult that scraper's input schema.
|
|
227
|
+
Read the output from the completed run's `result` field. Move `SerpConfig` to
|
|
228
|
+
`RaspbytesConfig(scraper=ScraperConfig(...))`.
|
|
229
|
+
|
|
230
|
+
## Async client
|
|
231
|
+
|
|
232
|
+
The async client exposes the same resource and method names:
|
|
233
|
+
|
|
234
|
+
```python
|
|
235
|
+
import asyncio
|
|
236
|
+
|
|
237
|
+
from raspbytes import AsyncRaspbytes
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
async def main() -> None:
|
|
241
|
+
async with AsyncRaspbytes() as client:
|
|
242
|
+
result = await client.scraper.hub.list(scope="raspbytes")
|
|
243
|
+
print(result)
|
|
244
|
+
|
|
245
|
+
|
|
246
|
+
asyncio.run(main())
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Configuration
|
|
250
|
+
|
|
251
|
+
Use `RaspbytesConfig` to share defaults across products, then configure individual products
|
|
252
|
+
with `ProxyConfig`, `BrowserConfig`, `UnblockerConfig`, or `ScraperConfig`. Both clients
|
|
253
|
+
accept the same configuration objects.
|
|
254
|
+
|
|
255
|
+
```python
|
|
256
|
+
from raspbytes import BrowserConfig, Raspbytes, RaspbytesConfig
|
|
257
|
+
|
|
258
|
+
config = RaspbytesConfig(
|
|
259
|
+
timeout=30,
|
|
260
|
+
max_retries=2,
|
|
261
|
+
browser=BrowserConfig(timeout=120, poll_timeout=90, poll_interval=0.5),
|
|
262
|
+
)
|
|
263
|
+
|
|
264
|
+
with Raspbytes(config=config) as client:
|
|
265
|
+
options = client.browser.proxy_options()
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
Product settings override constructor arguments for that product. Constructor arguments override
|
|
269
|
+
values in `RaspbytesConfig`. A polling argument such as `timeout=` on `scraper.runs.wait()`
|
|
270
|
+
applies to that call. The default API root is `https://api.raspbytes.com/api/v1/`.
|
|
271
|
+
|
|
272
|
+
## Errors
|
|
273
|
+
|
|
274
|
+
```python
|
|
275
|
+
from raspbytes import APIError, Raspbytes, RateLimitError, ScraperRunError
|
|
276
|
+
|
|
277
|
+
try:
|
|
278
|
+
with Raspbytes() as client:
|
|
279
|
+
client.scraper.runs.wait("run_id_from_submission", timeout=30)
|
|
280
|
+
except ScraperRunError as exc:
|
|
281
|
+
print(exc.request_id, exc.status, exc.code, exc.retryable)
|
|
282
|
+
except RateLimitError as exc:
|
|
283
|
+
print(exc.status_code, exc.code, exc.request_id)
|
|
284
|
+
except APIError as exc:
|
|
285
|
+
print(exc.status_code, exc.message, exc.body)
|
|
286
|
+
```
|
|
287
|
+
|
|
288
|
+
`APIError` exposes the HTTP status, message, and response body. The SDK raises more specific
|
|
289
|
+
exceptions for common failures such as rate limits. It retries connection establishment failures
|
|
290
|
+
and API responses marked as retryable, subject to the configured retry limit.
|
|
291
|
+
|
|
292
|
+
## Resources
|
|
293
|
+
|
|
294
|
+
- [Raspbytes API reference](https://docs.raspbytes.com/reference) for endpoints and schemas
|
|
295
|
+
- [Changelog](CHANGELOG.md) for SDK changes
|
|
296
|
+
- [BSD 2-Clause license](LICENSE)
|
|
297
|
+
- [Contributing](CONTRIBUTING.md) for SDK development
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
# Raspbytes Python SDK
|
|
2
|
+
|
|
3
|
+
The official Python SDK for Raspbytes provides synchronous and asynchronous clients for
|
|
4
|
+
Proxies, Browser API, Web Unblocker, and Scraper API. It includes typed requests, structured
|
|
5
|
+
API errors, and helpers for polling long-running operations.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
Requires Python 3.11 or later.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
python -m pip install raspbytes
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Authentication
|
|
16
|
+
|
|
17
|
+
Create an API key in the Raspbytes dashboard and set `RASPBYTES_API_KEY` in your environment.
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
export RASPBYTES_API_KEY='rb_live_your_key_here'
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Both clients read `RASPBYTES_API_KEY` automatically. You can also pass `api_key=` when
|
|
24
|
+
creating a client.
|
|
25
|
+
|
|
26
|
+
## Quick start
|
|
27
|
+
|
|
28
|
+
Fetch a page with Web Unblocker. The client context manager closes the HTTP connection pool.
|
|
29
|
+
|
|
30
|
+
```python
|
|
31
|
+
from raspbytes import Raspbytes, UnblockRequest
|
|
32
|
+
|
|
33
|
+
with Raspbytes() as client:
|
|
34
|
+
page = client.unblocker.retrieve(UnblockRequest(url="https://example.com"))
|
|
35
|
+
|
|
36
|
+
print(page["status"], page["http_status"])
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Proxies
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from raspbytes import ProxyConnectionParams, Raspbytes
|
|
43
|
+
|
|
44
|
+
with Raspbytes() as client:
|
|
45
|
+
connection = client.proxies.create(
|
|
46
|
+
ProxyConnectionParams(
|
|
47
|
+
proxy_type="residential",
|
|
48
|
+
country="US",
|
|
49
|
+
protocol="http",
|
|
50
|
+
)
|
|
51
|
+
)
|
|
52
|
+
proxy_url = connection["proxy_url"]
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Pass `proxy_url` directly to your HTTP client's proxy setting. The URL contains credentials.
|
|
56
|
+
Use `proxies.options()` to discover available locations and protocols for your account.
|
|
57
|
+
For a sticky connection, provide `session_type="sticky"` and a `session_id`. Use
|
|
58
|
+
`release_sticky_session(session_id)` to end the session early.
|
|
59
|
+
|
|
60
|
+
## Browser API
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
from raspbytes import BrowserProxy, BrowserSessionParams, Raspbytes
|
|
64
|
+
|
|
65
|
+
with Raspbytes() as client:
|
|
66
|
+
created = client.browser.create_session(
|
|
67
|
+
BrowserSessionParams(
|
|
68
|
+
browser="chromium",
|
|
69
|
+
proxy=BrowserProxy(type="datacenter", country="GB"),
|
|
70
|
+
session_timeout_seconds=900,
|
|
71
|
+
)
|
|
72
|
+
)
|
|
73
|
+
try:
|
|
74
|
+
session = client.browser.wait_until_ready(created["id"])
|
|
75
|
+
browser_url = session["connection"]["url"]
|
|
76
|
+
# Use browser_url with Playwright's chromium.connect_over_cdp().
|
|
77
|
+
finally:
|
|
78
|
+
client.browser.terminate_session(created["id"])
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Keep the browser WebSocket URL private. Use `browser.proxy_options()` to discover available
|
|
82
|
+
proxy options for your account.
|
|
83
|
+
|
|
84
|
+
## Web Unblocker
|
|
85
|
+
|
|
86
|
+
Use `retrieve()` to fetch a page in one request. To submit the request and collect the result
|
|
87
|
+
later, use `create_request()` and `wait_for_request()`.
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
from raspbytes import Raspbytes, UnblockRequest
|
|
91
|
+
|
|
92
|
+
with Raspbytes() as client:
|
|
93
|
+
queued = client.unblocker.create_request(UnblockRequest(url="https://example.com"))
|
|
94
|
+
completed = client.unblocker.wait_for_request(queued["id"], timeout=120)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Scraper API
|
|
98
|
+
|
|
99
|
+
Google, Bing, and DuckDuckGo are managed scrapers under `client.scraper`. The managed catalog
|
|
100
|
+
exports a typed input dictionary and a revision-pinned handle for each scraper.
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from uuid import uuid4
|
|
104
|
+
|
|
105
|
+
from raspbytes import Raspbytes
|
|
106
|
+
from raspbytes.managed_scrapers import GOOGLE_SEARCH, GoogleSearchInputs
|
|
107
|
+
|
|
108
|
+
with Raspbytes() as client:
|
|
109
|
+
scraper = client.scraper
|
|
110
|
+
inputs = GoogleSearchInputs(
|
|
111
|
+
query="coffee shops in London",
|
|
112
|
+
country="gb",
|
|
113
|
+
language="en",
|
|
114
|
+
device="desktop",
|
|
115
|
+
)
|
|
116
|
+
run = scraper.hub.run_managed(
|
|
117
|
+
GOOGLE_SEARCH,
|
|
118
|
+
inputs,
|
|
119
|
+
idempotency_key=str(uuid4()),
|
|
120
|
+
)
|
|
121
|
+
completed = scraper.runs.wait(run["id"], timeout=90)
|
|
122
|
+
print(completed.get("result"))
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
Use `hub.list()` and `hub.get()` to discover available scrapers, revisions, and input and
|
|
126
|
+
output schemas. For private or newly discovered scrapers, pass the Hub ID and inputs to
|
|
127
|
+
`hub.run()` or `hub.run_and_wait()`. Use the scraper's output schema to validate the `result`
|
|
128
|
+
field for your application.
|
|
129
|
+
|
|
130
|
+
Use `runs.iterate()` to stream run history across pages and `runs.cancel(run_id)` to cancel a
|
|
131
|
+
server-side run. Cancelling an asyncio task stops the local wait. An idempotency key enables
|
|
132
|
+
response retries for a submission when the service marks the failure retryable. Use a new key
|
|
133
|
+
for each logical run and reuse it when retrying that run.
|
|
134
|
+
|
|
135
|
+
`COUNTRIES` provides ISO country codes and display names. For managed search scrapers, the
|
|
136
|
+
`country` input selects the search market and `configuration.country` sets the execution origin.
|
|
137
|
+
|
|
138
|
+
### Manage Scraper workflows
|
|
139
|
+
|
|
140
|
+
Use `scraper.tasks` to save Hub inputs, create revisions, and run a saved task. Use
|
|
141
|
+
`scraper.schedules` to run a task on a cadence or submit an immediate run.
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from raspbytes import Raspbytes
|
|
145
|
+
from raspbytes.managed_scrapers import GOOGLE_SEARCH
|
|
146
|
+
from raspbytes.scraper_types import CreateScrapingTaskParams
|
|
147
|
+
|
|
148
|
+
task_request = CreateScrapingTaskParams(
|
|
149
|
+
scraper=GOOGLE_SEARCH.id,
|
|
150
|
+
revision=GOOGLE_SEARCH.revision,
|
|
151
|
+
name="London coffee shops",
|
|
152
|
+
configuration={
|
|
153
|
+
"inputs": {
|
|
154
|
+
"query": "coffee shops in London",
|
|
155
|
+
"country": "gb",
|
|
156
|
+
"language": "en",
|
|
157
|
+
"device": "desktop",
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
)
|
|
161
|
+
|
|
162
|
+
with Raspbytes() as client:
|
|
163
|
+
task = client.scraper.tasks.create(task_request)
|
|
164
|
+
schedule = client.scraper.schedules.create(
|
|
165
|
+
{
|
|
166
|
+
"task": task["id"],
|
|
167
|
+
"name": "Weekday refresh",
|
|
168
|
+
"frequency": "custom",
|
|
169
|
+
"weekdays": [1, 2, 3, 4, 5],
|
|
170
|
+
"timezone": "Europe/London",
|
|
171
|
+
"time_of_day": "09:00:00",
|
|
172
|
+
}
|
|
173
|
+
)
|
|
174
|
+
run = client.scraper.schedules.run_now(schedule["id"])
|
|
175
|
+
finished = client.scraper.runs.wait(run["id"], timeout=90)
|
|
176
|
+
artifacts = client.scraper.storage.list_for_run(finished["id"])
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
- `storage.iterate()` streams retained outputs. `create_download_link()` returns a short-lived
|
|
180
|
+
URL that should be treated as a secret.
|
|
181
|
+
- `monitoring.get(scope_type="task", scope_id=task_id, window="24h")` reads task metrics.
|
|
182
|
+
`list_scopes()` discovers available scopes. Policy methods read, patch, or evaluate alerts.
|
|
183
|
+
- `builder` manages account-owned scrapers, immutable revisions, access shares, and publication.
|
|
184
|
+
- `schedules.pause()` and `schedules.resume()` set an explicit enabled state. Use
|
|
185
|
+
`toggle_pause()` when you want the API to flip the current state.
|
|
186
|
+
|
|
187
|
+
Request and response types are available from `raspbytes.scraper_types`. With
|
|
188
|
+
`AsyncRaspbytes`, await the same methods and use `async for` with `storage.iterate()`.
|
|
189
|
+
|
|
190
|
+
### Migrating from SERP
|
|
191
|
+
|
|
192
|
+
Replace `client.serp` with `client.scraper`. Choose `GOOGLE_SEARCH`, `BING_SEARCH`, or
|
|
193
|
+
`DUCKDUCKGO_SEARCH` in place of the old engine argument, and consult that scraper's input schema.
|
|
194
|
+
Read the output from the completed run's `result` field. Move `SerpConfig` to
|
|
195
|
+
`RaspbytesConfig(scraper=ScraperConfig(...))`.
|
|
196
|
+
|
|
197
|
+
## Async client
|
|
198
|
+
|
|
199
|
+
The async client exposes the same resource and method names:
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
import asyncio
|
|
203
|
+
|
|
204
|
+
from raspbytes import AsyncRaspbytes
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
async def main() -> None:
|
|
208
|
+
async with AsyncRaspbytes() as client:
|
|
209
|
+
result = await client.scraper.hub.list(scope="raspbytes")
|
|
210
|
+
print(result)
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
asyncio.run(main())
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
## Configuration
|
|
217
|
+
|
|
218
|
+
Use `RaspbytesConfig` to share defaults across products, then configure individual products
|
|
219
|
+
with `ProxyConfig`, `BrowserConfig`, `UnblockerConfig`, or `ScraperConfig`. Both clients
|
|
220
|
+
accept the same configuration objects.
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
from raspbytes import BrowserConfig, Raspbytes, RaspbytesConfig
|
|
224
|
+
|
|
225
|
+
config = RaspbytesConfig(
|
|
226
|
+
timeout=30,
|
|
227
|
+
max_retries=2,
|
|
228
|
+
browser=BrowserConfig(timeout=120, poll_timeout=90, poll_interval=0.5),
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
with Raspbytes(config=config) as client:
|
|
232
|
+
options = client.browser.proxy_options()
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
Product settings override constructor arguments for that product. Constructor arguments override
|
|
236
|
+
values in `RaspbytesConfig`. A polling argument such as `timeout=` on `scraper.runs.wait()`
|
|
237
|
+
applies to that call. The default API root is `https://api.raspbytes.com/api/v1/`.
|
|
238
|
+
|
|
239
|
+
## Errors
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
from raspbytes import APIError, Raspbytes, RateLimitError, ScraperRunError
|
|
243
|
+
|
|
244
|
+
try:
|
|
245
|
+
with Raspbytes() as client:
|
|
246
|
+
client.scraper.runs.wait("run_id_from_submission", timeout=30)
|
|
247
|
+
except ScraperRunError as exc:
|
|
248
|
+
print(exc.request_id, exc.status, exc.code, exc.retryable)
|
|
249
|
+
except RateLimitError as exc:
|
|
250
|
+
print(exc.status_code, exc.code, exc.request_id)
|
|
251
|
+
except APIError as exc:
|
|
252
|
+
print(exc.status_code, exc.message, exc.body)
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
`APIError` exposes the HTTP status, message, and response body. The SDK raises more specific
|
|
256
|
+
exceptions for common failures such as rate limits. It retries connection establishment failures
|
|
257
|
+
and API responses marked as retryable, subject to the configured retry limit.
|
|
258
|
+
|
|
259
|
+
## Resources
|
|
260
|
+
|
|
261
|
+
- [Raspbytes API reference](https://docs.raspbytes.com/reference) for endpoints and schemas
|
|
262
|
+
- [Changelog](CHANGELOG.md) for SDK changes
|
|
263
|
+
- [BSD 2-Clause license](LICENSE)
|
|
264
|
+
- [Contributing](CONTRIBUTING.md) for SDK development
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "raspbytes"
|
|
3
|
+
version = "1.1.0"
|
|
4
|
+
description = "Official Python SDK for the Raspbytes API"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "BSD-2-Clause"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "Raspbytes" }]
|
|
10
|
+
keywords = ["raspbytes", "proxy", "scraping", "browser-api"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 3 - Alpha",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Programming Language :: Python :: 3.14",
|
|
20
|
+
"Typing :: Typed",
|
|
21
|
+
]
|
|
22
|
+
dependencies = ["httpx>=0.27,<1"]
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Documentation = "https://docs.raspbytes.com/reference"
|
|
26
|
+
Homepage = "https://raspbytes.com"
|
|
27
|
+
Issues = "https://github.com/raspbytes-labs/python-sdk/issues"
|
|
28
|
+
Repository = "https://github.com/raspbytes-labs/python-sdk"
|
|
29
|
+
Changelog = "https://github.com/raspbytes-labs/python-sdk/blob/main/CHANGELOG.md"
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dev = [
|
|
33
|
+
"mypy>=1.13,<2",
|
|
34
|
+
"pytest>=8,<9",
|
|
35
|
+
"pytest-asyncio>=1.4.1,<2",
|
|
36
|
+
"pytest-cov>=6,<8",
|
|
37
|
+
"ruff>=0.8,<1",
|
|
38
|
+
"twine>=7,<8",
|
|
39
|
+
]
|
|
40
|
+
|
|
41
|
+
[build-system]
|
|
42
|
+
requires = ["hatchling"]
|
|
43
|
+
build-backend = "hatchling.build"
|
|
44
|
+
|
|
45
|
+
[tool.hatch.build.targets.wheel]
|
|
46
|
+
packages = ["src/raspbytes"]
|
|
47
|
+
|
|
48
|
+
[tool.hatch.build.targets.sdist]
|
|
49
|
+
include = ["/src", "/README.md", "/LICENSE", "/pyproject.toml"]
|
|
50
|
+
|
|
51
|
+
[tool.pytest.ini_options]
|
|
52
|
+
testpaths = ["tests"]
|
|
53
|
+
pythonpath = ["."]
|
|
54
|
+
asyncio_mode = "auto"
|
|
55
|
+
addopts = "--strict-config --strict-markers"
|
|
56
|
+
|
|
57
|
+
[tool.coverage.run]
|
|
58
|
+
branch = true
|
|
59
|
+
source = ["raspbytes"]
|
|
60
|
+
|
|
61
|
+
[tool.coverage.report]
|
|
62
|
+
fail_under = 95
|
|
63
|
+
show_missing = true
|
|
64
|
+
skip_covered = true
|
|
65
|
+
|
|
66
|
+
[tool.ruff]
|
|
67
|
+
line-length = 100
|
|
68
|
+
target-version = "py311"
|
|
69
|
+
|
|
70
|
+
[tool.ruff.lint]
|
|
71
|
+
select = ["E", "F", "I", "UP", "B"]
|
|
72
|
+
|
|
73
|
+
[tool.mypy]
|
|
74
|
+
python_version = "3.11"
|
|
75
|
+
strict = true
|
|
76
|
+
files = ["src/raspbytes"]
|
|
77
|
+
pretty = true
|
|
78
|
+
|
|
79
|
+
[tool.semantic_release]
|
|
80
|
+
allow_zero_version = false
|
|
81
|
+
commit_parser = "conventional"
|
|
82
|
+
commit_message = "chore(release): v{version} [skip ci]"
|
|
83
|
+
tag_format = "v{version}"
|
|
84
|
+
version_toml = ["pyproject.toml:project.version"]
|
|
85
|
+
build_command = """
|
|
86
|
+
python -m pip install 'uv==0.13.5'
|
|
87
|
+
uv lock --upgrade-package "$PACKAGE_NAME"
|
|
88
|
+
git add uv.lock
|
|
89
|
+
"""
|
|
90
|
+
|
|
91
|
+
[tool.semantic_release.branches.main]
|
|
92
|
+
match = "main"
|
|
93
|
+
prerelease = false
|
|
94
|
+
|
|
95
|
+
[tool.semantic_release.changelog.default_templates]
|
|
96
|
+
changelog_file = "CHANGELOG.md"
|
|
97
|
+
mask_initial_release = false
|
|
98
|
+
|
|
99
|
+
[tool.semantic_release.publish]
|
|
100
|
+
dist_glob_patterns = ["dist/*"]
|