screenshotapi-to 1.0.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.
@@ -0,0 +1,9 @@
1
+ __pycache__/
2
+ *.py[cod]
3
+ *.egg-info/
4
+ .mypy_cache/
5
+ .pytest_cache/
6
+ .ruff_cache/
7
+ .venv/
8
+ build/
9
+ dist/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 ScreenshotAPI
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,311 @@
1
+ Metadata-Version: 2.4
2
+ Name: screenshotapi-to
3
+ Version: 1.0.0
4
+ Summary: Official Python SDK for ScreenshotAPI.
5
+ Project-URL: Homepage, https://screenshotapi.to
6
+ Project-URL: Documentation, https://screenshotapi.to/docs
7
+ Project-URL: Pricing, https://screenshotapi.to/pricing
8
+ Project-URL: Repository, https://github.com/miketromba/screenshotapi-python
9
+ Project-URL: Issues, https://github.com/miketromba/screenshotapi-python/issues
10
+ Project-URL: Support, https://screenshotapi.to
11
+ Author-email: ScreenshotAPI <support@screenshotapi.to>
12
+ Maintainer-email: ScreenshotAPI <support@screenshotapi.to>
13
+ License: MIT License
14
+
15
+ Copyright (c) 2026 ScreenshotAPI
16
+
17
+ Permission is hereby granted, free of charge, to any person obtaining a copy
18
+ of this software and associated documentation files (the "Software"), to deal
19
+ in the Software without restriction, including without limitation the rights
20
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
21
+ copies of the Software, and to permit persons to whom the Software is
22
+ furnished to do so, subject to the following conditions:
23
+
24
+ The above copyright notice and this permission notice shall be included in all
25
+ copies or substantial portions of the Software.
26
+
27
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
+ SOFTWARE.
34
+ License-File: LICENSE
35
+ Keywords: api,capture,html-to-image,screenshot,screenshotapi,webpage,website-thumbnail
36
+ Classifier: Development Status :: 5 - Production/Stable
37
+ Classifier: Environment :: Web Environment
38
+ Classifier: Intended Audience :: Developers
39
+ Classifier: License :: OSI Approved :: MIT License
40
+ Classifier: Operating System :: OS Independent
41
+ Classifier: Programming Language :: Python :: 3
42
+ Classifier: Programming Language :: Python :: 3 :: Only
43
+ Classifier: Programming Language :: Python :: 3.8
44
+ Classifier: Programming Language :: Python :: 3.9
45
+ Classifier: Programming Language :: Python :: 3.10
46
+ Classifier: Programming Language :: Python :: 3.11
47
+ Classifier: Programming Language :: Python :: 3.12
48
+ Classifier: Programming Language :: Python :: 3.13
49
+ Classifier: Topic :: Internet :: WWW/HTTP
50
+ Classifier: Topic :: Multimedia :: Graphics :: Capture :: Screen Capture
51
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
52
+ Classifier: Typing :: Typed
53
+ Requires-Python: >=3.8
54
+ Requires-Dist: httpx<1.0,>=0.24.0
55
+ Provides-Extra: dev
56
+ Requires-Dist: build>=1.2; extra == 'dev'
57
+ Requires-Dist: mypy<1.15,>=1.8; extra == 'dev'
58
+ Requires-Dist: ruff>=0.8; extra == 'dev'
59
+ Requires-Dist: twine>=5.0; extra == 'dev'
60
+ Provides-Extra: test
61
+ Requires-Dist: pytest-asyncio>=0.23; extra == 'test'
62
+ Requires-Dist: pytest>=8.0; extra == 'test'
63
+ Description-Content-Type: text/markdown
64
+
65
+ # screenshotapi
66
+
67
+ Official typed Python SDK for
68
+ [ScreenshotAPI](https://screenshotapi.to?utm_source=pypi&utm_medium=python-sdk&utm_campaign=sdk-readme&ref=python-sdk),
69
+ the hosted screenshot API for turning URLs or HTML into PNG, JPEG, WebP, or PDF
70
+ captures.
71
+
72
+ ## Install
73
+
74
+ ```bash
75
+ pip install screenshotapi-to
76
+ ```
77
+
78
+ Python 3.8+ is supported. The distribution package is `screenshotapi-to`, the
79
+ import package is `screenshotapi`, and the package ships `py.typed` metadata for
80
+ type checkers.
81
+
82
+ ## Authentication
83
+
84
+ Create an API key in the ScreenshotAPI dashboard, then keep it in an environment
85
+ variable:
86
+
87
+ ```bash
88
+ export SCREENSHOTAPI_KEY="sk_live_your_key_here"
89
+ ```
90
+
91
+ The SDK sends your key in the `x-api-key` header. Keep API keys on the server;
92
+ do not expose them in browser bundles or mobile apps.
93
+
94
+ ## First Screenshot
95
+
96
+ ```python
97
+ import os
98
+
99
+ from screenshotapi import ScreenshotAPI
100
+
101
+ client = ScreenshotAPI(os.environ["SCREENSHOTAPI_KEY"])
102
+
103
+ metadata = client.save(
104
+ {
105
+ "url": "https://example.com",
106
+ "width": 1440,
107
+ "height": 900,
108
+ },
109
+ "screenshot.png",
110
+ )
111
+
112
+ print(f"Screenshot ID: {metadata.screenshot_id}")
113
+ print(f"Credits remaining: {metadata.credits_remaining}")
114
+ ```
115
+
116
+ ## Usage
117
+
118
+ ### Initialize the Client
119
+
120
+ ```python
121
+ from screenshotapi import ScreenshotAPI
122
+
123
+ client = ScreenshotAPI(
124
+ "sk_live_your_key_here",
125
+ base_url="https://screenshotapi.to",
126
+ timeout=60.0,
127
+ )
128
+ ```
129
+
130
+ ### Capture Bytes
131
+
132
+ ```python
133
+ from screenshotapi import ScreenshotOptions
134
+
135
+ result = client.screenshot(
136
+ ScreenshotOptions(
137
+ url="https://example.com",
138
+ full_page=True,
139
+ type="webp",
140
+ quality=90,
141
+ color_scheme="dark",
142
+ )
143
+ )
144
+
145
+ image_bytes = result.image
146
+ content_type = result.content_type
147
+ credits_remaining = result.metadata.credits_remaining
148
+ ```
149
+
150
+ Plain dictionaries are also supported:
151
+
152
+ ```python
153
+ result = client.screenshot(
154
+ {
155
+ "url": "https://example.com",
156
+ "full_page": True,
157
+ "type": "webp",
158
+ }
159
+ )
160
+ ```
161
+
162
+ ### Async Capture
163
+
164
+ ```python
165
+ import asyncio
166
+ import os
167
+
168
+ from screenshotapi import ScreenshotAPI
169
+
170
+ client = ScreenshotAPI(os.environ["SCREENSHOTAPI_KEY"])
171
+
172
+
173
+ async def main() -> None:
174
+ result = await client.async_screenshot({"url": "https://example.com"})
175
+ print(f"Duration: {result.metadata.duration_ms}ms")
176
+
177
+ await client.async_save({"url": "https://example.com"}, "screenshot.png")
178
+
179
+
180
+ asyncio.run(main())
181
+ ```
182
+
183
+ ## Advanced Options
184
+
185
+ ```python
186
+ result = client.screenshot(
187
+ {
188
+ "url": "https://example.com/dashboard",
189
+ "width": 1280,
190
+ "height": 720,
191
+ "device_pixel_ratio": 2,
192
+ "full_page": False,
193
+ "type": "webp",
194
+ "quality": 85,
195
+ "color_scheme": "dark",
196
+ "wait_until": "networkidle0",
197
+ "wait_for_selector": ".ready",
198
+ "delay": 500,
199
+ "block_ads": True,
200
+ "remove_cookie_banners": True,
201
+ "remove_popups": True,
202
+ "remove_elements": [".newsletter", "#cookie-banner"],
203
+ "css_inject": "body { caret-color: transparent; }",
204
+ "js_inject": "window.scrollTo(0, 0)",
205
+ "stealth_mode": True,
206
+ "timezone": "America/New_York",
207
+ "locale": "en-US",
208
+ "cache_ttl": 3600,
209
+ "preload_fonts": True,
210
+ "geo_latitude": 40.7128,
211
+ "geo_longitude": -74.0060,
212
+ "geo_accuracy": 25,
213
+ }
214
+ )
215
+ ```
216
+
217
+ HTML rendering uses `POST /api/v1/screenshot` automatically:
218
+
219
+ ```python
220
+ result = client.screenshot(
221
+ {
222
+ "html": "<html><body><h1>Invoice #123</h1></body></html>",
223
+ "type": "pdf",
224
+ }
225
+ )
226
+ ```
227
+
228
+ Supported options:
229
+
230
+ | Python option | API parameter | Notes |
231
+ |---|---|---|
232
+ | `url` | `url` | Required unless `html` is provided |
233
+ | `html` | `html` | Raw HTML, sent with POST |
234
+ | `width`, `height` | `width`, `height` | Viewport size |
235
+ | `full_page` | `fullPage` | Capture full scrollable page |
236
+ | `type` | `type` | `png`, `jpeg`, `webp`, or `pdf` |
237
+ | `quality` | `quality` | JPEG/WebP quality, 1-100 |
238
+ | `color_scheme` | `colorScheme` | `light` or `dark` |
239
+ | `wait_until` | `waitUntil` | `load`, `domcontentloaded`, `networkidle0`, `networkidle2` |
240
+ | `wait_for_selector` | `waitForSelector` | CSS selector to wait for |
241
+ | `delay` | `delay` | Extra delay in milliseconds |
242
+ | `block_ads` | `blockAds` | Remove ads before capture |
243
+ | `remove_cookie_banners` | `removeCookieBanners` | Remove common consent banners |
244
+ | `css_inject`, `js_inject` | `cssInject`, `jsInject` | Inject CSS or JavaScript before capture |
245
+ | `stealth_mode` | `stealthMode` | Enable anti-bot fingerprint masking |
246
+ | `device_pixel_ratio` | `devicePixelRatio` | `1`, `2`, or `3` |
247
+ | `timezone`, `locale` | `timezone`, `locale` | Browser emulation settings |
248
+ | `cache_ttl` | `cacheTtl` | Cache identical captures for N seconds |
249
+ | `preload_fonts` | `preloadFonts` | Preload Google Fonts before capture |
250
+ | `remove_elements` | `removeElements` | CSS selectors to remove |
251
+ | `remove_popups` | `removePopups` | Remove common overlays and modals |
252
+ | `mockup_device` | `mockupDevice` | `browser`, `iphone`, or `macbook` frame |
253
+ | `geo_latitude`, `geo_longitude`, `geo_accuracy` | `geoLocation` or geo query params | Browser geolocation override |
254
+
255
+ ## Error Handling
256
+
257
+ ```python
258
+ from screenshotapi import (
259
+ AuthenticationError,
260
+ InsufficientCreditsError,
261
+ InvalidAPIKeyError,
262
+ NetworkError,
263
+ ScreenshotAPI,
264
+ ScreenshotAPIError,
265
+ ScreenshotFailedError,
266
+ )
267
+
268
+ client = ScreenshotAPI("sk_live_your_key_here")
269
+
270
+ try:
271
+ client.screenshot({"url": "https://example.com"})
272
+ except AuthenticationError:
273
+ print("Missing API key")
274
+ except InvalidAPIKeyError:
275
+ print("Invalid or revoked API key")
276
+ except InsufficientCreditsError as exc:
277
+ print(f"No credits remaining. Balance: {exc.balance}")
278
+ except ScreenshotFailedError as exc:
279
+ print(f"Screenshot failed: {exc}")
280
+ except NetworkError as exc:
281
+ print(f"Could not reach ScreenshotAPI: {exc}")
282
+ except ScreenshotAPIError as exc:
283
+ print(f"ScreenshotAPI error {exc.status} ({exc.code}): {exc}")
284
+ ```
285
+
286
+ ## Examples
287
+
288
+ Runnable examples live in `examples/`:
289
+
290
+ - `script_usage.py` for one-off scripts and cron jobs
291
+ - `fastapi_app.py` for FastAPI endpoints
292
+ - `django_view.py` for Django views
293
+ - `flask_app.py` for Flask routes
294
+
295
+ ## Pricing and Free Tier
296
+
297
+ ScreenshotAPI includes
298
+ [200 free screenshots per month](https://screenshotapi.to/pricing?utm_source=pypi&utm_medium=python-sdk&utm_campaign=sdk-readme&ref=python-sdk)
299
+ with no credit card required. Paid subscriptions and credit packs are available
300
+ when you need more volume.
301
+
302
+ ## Links
303
+
304
+ - [Documentation](https://screenshotapi.to/docs?utm_source=pypi&utm_medium=python-sdk&utm_campaign=sdk-readme&ref=python-sdk)
305
+ - [Screenshot API reference](https://screenshotapi.to/docs/api/screenshot?utm_source=pypi&utm_medium=python-sdk&utm_campaign=sdk-readme&ref=python-sdk)
306
+ - [Pricing](https://screenshotapi.to/pricing?utm_source=pypi&utm_medium=python-sdk&utm_campaign=sdk-readme&ref=python-sdk)
307
+ - [Support](mailto:support@screenshotapi.to?subject=Python%20SDK%20support)
308
+
309
+ ## License
310
+
311
+ MIT
@@ -0,0 +1,247 @@
1
+ # screenshotapi
2
+
3
+ Official typed Python SDK for
4
+ [ScreenshotAPI](https://screenshotapi.to?utm_source=pypi&utm_medium=python-sdk&utm_campaign=sdk-readme&ref=python-sdk),
5
+ the hosted screenshot API for turning URLs or HTML into PNG, JPEG, WebP, or PDF
6
+ captures.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ pip install screenshotapi-to
12
+ ```
13
+
14
+ Python 3.8+ is supported. The distribution package is `screenshotapi-to`, the
15
+ import package is `screenshotapi`, and the package ships `py.typed` metadata for
16
+ type checkers.
17
+
18
+ ## Authentication
19
+
20
+ Create an API key in the ScreenshotAPI dashboard, then keep it in an environment
21
+ variable:
22
+
23
+ ```bash
24
+ export SCREENSHOTAPI_KEY="sk_live_your_key_here"
25
+ ```
26
+
27
+ The SDK sends your key in the `x-api-key` header. Keep API keys on the server;
28
+ do not expose them in browser bundles or mobile apps.
29
+
30
+ ## First Screenshot
31
+
32
+ ```python
33
+ import os
34
+
35
+ from screenshotapi import ScreenshotAPI
36
+
37
+ client = ScreenshotAPI(os.environ["SCREENSHOTAPI_KEY"])
38
+
39
+ metadata = client.save(
40
+ {
41
+ "url": "https://example.com",
42
+ "width": 1440,
43
+ "height": 900,
44
+ },
45
+ "screenshot.png",
46
+ )
47
+
48
+ print(f"Screenshot ID: {metadata.screenshot_id}")
49
+ print(f"Credits remaining: {metadata.credits_remaining}")
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ ### Initialize the Client
55
+
56
+ ```python
57
+ from screenshotapi import ScreenshotAPI
58
+
59
+ client = ScreenshotAPI(
60
+ "sk_live_your_key_here",
61
+ base_url="https://screenshotapi.to",
62
+ timeout=60.0,
63
+ )
64
+ ```
65
+
66
+ ### Capture Bytes
67
+
68
+ ```python
69
+ from screenshotapi import ScreenshotOptions
70
+
71
+ result = client.screenshot(
72
+ ScreenshotOptions(
73
+ url="https://example.com",
74
+ full_page=True,
75
+ type="webp",
76
+ quality=90,
77
+ color_scheme="dark",
78
+ )
79
+ )
80
+
81
+ image_bytes = result.image
82
+ content_type = result.content_type
83
+ credits_remaining = result.metadata.credits_remaining
84
+ ```
85
+
86
+ Plain dictionaries are also supported:
87
+
88
+ ```python
89
+ result = client.screenshot(
90
+ {
91
+ "url": "https://example.com",
92
+ "full_page": True,
93
+ "type": "webp",
94
+ }
95
+ )
96
+ ```
97
+
98
+ ### Async Capture
99
+
100
+ ```python
101
+ import asyncio
102
+ import os
103
+
104
+ from screenshotapi import ScreenshotAPI
105
+
106
+ client = ScreenshotAPI(os.environ["SCREENSHOTAPI_KEY"])
107
+
108
+
109
+ async def main() -> None:
110
+ result = await client.async_screenshot({"url": "https://example.com"})
111
+ print(f"Duration: {result.metadata.duration_ms}ms")
112
+
113
+ await client.async_save({"url": "https://example.com"}, "screenshot.png")
114
+
115
+
116
+ asyncio.run(main())
117
+ ```
118
+
119
+ ## Advanced Options
120
+
121
+ ```python
122
+ result = client.screenshot(
123
+ {
124
+ "url": "https://example.com/dashboard",
125
+ "width": 1280,
126
+ "height": 720,
127
+ "device_pixel_ratio": 2,
128
+ "full_page": False,
129
+ "type": "webp",
130
+ "quality": 85,
131
+ "color_scheme": "dark",
132
+ "wait_until": "networkidle0",
133
+ "wait_for_selector": ".ready",
134
+ "delay": 500,
135
+ "block_ads": True,
136
+ "remove_cookie_banners": True,
137
+ "remove_popups": True,
138
+ "remove_elements": [".newsletter", "#cookie-banner"],
139
+ "css_inject": "body { caret-color: transparent; }",
140
+ "js_inject": "window.scrollTo(0, 0)",
141
+ "stealth_mode": True,
142
+ "timezone": "America/New_York",
143
+ "locale": "en-US",
144
+ "cache_ttl": 3600,
145
+ "preload_fonts": True,
146
+ "geo_latitude": 40.7128,
147
+ "geo_longitude": -74.0060,
148
+ "geo_accuracy": 25,
149
+ }
150
+ )
151
+ ```
152
+
153
+ HTML rendering uses `POST /api/v1/screenshot` automatically:
154
+
155
+ ```python
156
+ result = client.screenshot(
157
+ {
158
+ "html": "<html><body><h1>Invoice #123</h1></body></html>",
159
+ "type": "pdf",
160
+ }
161
+ )
162
+ ```
163
+
164
+ Supported options:
165
+
166
+ | Python option | API parameter | Notes |
167
+ |---|---|---|
168
+ | `url` | `url` | Required unless `html` is provided |
169
+ | `html` | `html` | Raw HTML, sent with POST |
170
+ | `width`, `height` | `width`, `height` | Viewport size |
171
+ | `full_page` | `fullPage` | Capture full scrollable page |
172
+ | `type` | `type` | `png`, `jpeg`, `webp`, or `pdf` |
173
+ | `quality` | `quality` | JPEG/WebP quality, 1-100 |
174
+ | `color_scheme` | `colorScheme` | `light` or `dark` |
175
+ | `wait_until` | `waitUntil` | `load`, `domcontentloaded`, `networkidle0`, `networkidle2` |
176
+ | `wait_for_selector` | `waitForSelector` | CSS selector to wait for |
177
+ | `delay` | `delay` | Extra delay in milliseconds |
178
+ | `block_ads` | `blockAds` | Remove ads before capture |
179
+ | `remove_cookie_banners` | `removeCookieBanners` | Remove common consent banners |
180
+ | `css_inject`, `js_inject` | `cssInject`, `jsInject` | Inject CSS or JavaScript before capture |
181
+ | `stealth_mode` | `stealthMode` | Enable anti-bot fingerprint masking |
182
+ | `device_pixel_ratio` | `devicePixelRatio` | `1`, `2`, or `3` |
183
+ | `timezone`, `locale` | `timezone`, `locale` | Browser emulation settings |
184
+ | `cache_ttl` | `cacheTtl` | Cache identical captures for N seconds |
185
+ | `preload_fonts` | `preloadFonts` | Preload Google Fonts before capture |
186
+ | `remove_elements` | `removeElements` | CSS selectors to remove |
187
+ | `remove_popups` | `removePopups` | Remove common overlays and modals |
188
+ | `mockup_device` | `mockupDevice` | `browser`, `iphone`, or `macbook` frame |
189
+ | `geo_latitude`, `geo_longitude`, `geo_accuracy` | `geoLocation` or geo query params | Browser geolocation override |
190
+
191
+ ## Error Handling
192
+
193
+ ```python
194
+ from screenshotapi import (
195
+ AuthenticationError,
196
+ InsufficientCreditsError,
197
+ InvalidAPIKeyError,
198
+ NetworkError,
199
+ ScreenshotAPI,
200
+ ScreenshotAPIError,
201
+ ScreenshotFailedError,
202
+ )
203
+
204
+ client = ScreenshotAPI("sk_live_your_key_here")
205
+
206
+ try:
207
+ client.screenshot({"url": "https://example.com"})
208
+ except AuthenticationError:
209
+ print("Missing API key")
210
+ except InvalidAPIKeyError:
211
+ print("Invalid or revoked API key")
212
+ except InsufficientCreditsError as exc:
213
+ print(f"No credits remaining. Balance: {exc.balance}")
214
+ except ScreenshotFailedError as exc:
215
+ print(f"Screenshot failed: {exc}")
216
+ except NetworkError as exc:
217
+ print(f"Could not reach ScreenshotAPI: {exc}")
218
+ except ScreenshotAPIError as exc:
219
+ print(f"ScreenshotAPI error {exc.status} ({exc.code}): {exc}")
220
+ ```
221
+
222
+ ## Examples
223
+
224
+ Runnable examples live in `examples/`:
225
+
226
+ - `script_usage.py` for one-off scripts and cron jobs
227
+ - `fastapi_app.py` for FastAPI endpoints
228
+ - `django_view.py` for Django views
229
+ - `flask_app.py` for Flask routes
230
+
231
+ ## Pricing and Free Tier
232
+
233
+ ScreenshotAPI includes
234
+ [200 free screenshots per month](https://screenshotapi.to/pricing?utm_source=pypi&utm_medium=python-sdk&utm_campaign=sdk-readme&ref=python-sdk)
235
+ with no credit card required. Paid subscriptions and credit packs are available
236
+ when you need more volume.
237
+
238
+ ## Links
239
+
240
+ - [Documentation](https://screenshotapi.to/docs?utm_source=pypi&utm_medium=python-sdk&utm_campaign=sdk-readme&ref=python-sdk)
241
+ - [Screenshot API reference](https://screenshotapi.to/docs/api/screenshot?utm_source=pypi&utm_medium=python-sdk&utm_campaign=sdk-readme&ref=python-sdk)
242
+ - [Pricing](https://screenshotapi.to/pricing?utm_source=pypi&utm_medium=python-sdk&utm_campaign=sdk-readme&ref=python-sdk)
243
+ - [Support](mailto:support@screenshotapi.to?subject=Python%20SDK%20support)
244
+
245
+ ## License
246
+
247
+ MIT
@@ -0,0 +1,32 @@
1
+ from __future__ import annotations
2
+
3
+ from django.conf import settings
4
+ from django.http import HttpRequest, HttpResponse, JsonResponse
5
+
6
+ from screenshotapi import ScreenshotAPI, ScreenshotAPIError
7
+
8
+
9
+ def screenshot_view(request: HttpRequest) -> HttpResponse:
10
+ url = request.GET.get("url")
11
+ if not url:
12
+ return JsonResponse({"error": "url is required"}, status=400)
13
+
14
+ client = ScreenshotAPI(settings.SCREENSHOTAPI_KEY)
15
+
16
+ try:
17
+ result = client.screenshot(
18
+ {
19
+ "url": url,
20
+ "width": 1280,
21
+ "height": 720,
22
+ "type": "png",
23
+ "cache_ttl": 3600,
24
+ }
25
+ )
26
+ except ScreenshotAPIError as exc:
27
+ return JsonResponse({"error": str(exc), "code": exc.code}, status=502)
28
+
29
+ response = HttpResponse(result.image, content_type=result.content_type)
30
+ response["x-screenshot-id"] = result.metadata.screenshot_id
31
+ response["x-credits-remaining"] = str(result.metadata.credits_remaining)
32
+ return response
@@ -0,0 +1,29 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+
5
+ from fastapi import FastAPI, HTTPException, Response
6
+
7
+ from screenshotapi import ScreenshotAPI, ScreenshotAPIError
8
+
9
+ app = FastAPI()
10
+ client = ScreenshotAPI(os.environ["SCREENSHOTAPI_KEY"])
11
+
12
+
13
+ @app.get("/screenshot")
14
+ def screenshot(url: str) -> Response:
15
+ try:
16
+ result = client.screenshot(
17
+ {
18
+ "url": url,
19
+ "type": "webp",
20
+ "width": 1440,
21
+ "height": 900,
22
+ "block_ads": True,
23
+ "remove_cookie_banners": True,
24
+ }
25
+ )
26
+ except ScreenshotAPIError as exc:
27
+ raise HTTPException(status_code=502, detail=str(exc)) from exc
28
+
29
+ return Response(content=result.image, media_type=result.content_type)
@@ -0,0 +1,31 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+
5
+ from flask import Flask, Response, jsonify, request
6
+
7
+ from screenshotapi import ScreenshotAPI, ScreenshotAPIError
8
+
9
+ app = Flask(__name__)
10
+ client = ScreenshotAPI(os.environ["SCREENSHOTAPI_KEY"])
11
+
12
+
13
+ @app.get("/screenshot")
14
+ def screenshot() -> Response:
15
+ url = request.args.get("url")
16
+ if not url:
17
+ return jsonify({"error": "url is required"}), 400
18
+
19
+ try:
20
+ result = client.screenshot(
21
+ {
22
+ "url": url,
23
+ "full_page": request.args.get("full_page") == "true",
24
+ "type": "jpeg",
25
+ "quality": 85,
26
+ }
27
+ )
28
+ except ScreenshotAPIError as exc:
29
+ return jsonify({"error": str(exc), "code": exc.code}), 502
30
+
31
+ return Response(result.image, mimetype=result.content_type)