Official Python SDK for ScreenshotAPI.
Project description
screenshotapi
Official typed Python SDK for ScreenshotAPI, the hosted screenshot API for turning URLs or HTML into PNG, JPEG, WebP, or PDF captures.
Install
pip install screenshotapi-to
Python 3.8+ is supported. The distribution package is screenshotapi-to, the
import package is screenshotapi, and the package ships py.typed metadata for
type checkers.
Authentication
Create an API key in the ScreenshotAPI dashboard, then keep it in an environment variable:
export SCREENSHOTAPI_KEY="sk_live_your_key_here"
The SDK sends your key in the x-api-key header. Keep API keys on the server;
do not expose them in browser bundles or mobile apps.
First Screenshot
import os
from screenshotapi import ScreenshotAPI
client = ScreenshotAPI(os.environ["SCREENSHOTAPI_KEY"])
metadata = client.save(
{
"url": "https://example.com",
"width": 1440,
"height": 900,
},
"screenshot.png",
)
print(f"Screenshot ID: {metadata.screenshot_id}")
print(f"Credits remaining: {metadata.credits_remaining}")
Usage
Initialize the Client
from screenshotapi import ScreenshotAPI
client = ScreenshotAPI(
"sk_live_your_key_here",
base_url="https://screenshotapi.to",
timeout=60.0,
)
Capture Bytes
from screenshotapi import ScreenshotOptions
result = client.screenshot(
ScreenshotOptions(
url="https://example.com",
full_page=True,
type="webp",
quality=90,
color_scheme="dark",
)
)
image_bytes = result.image
content_type = result.content_type
credits_remaining = result.metadata.credits_remaining
Plain dictionaries are also supported:
result = client.screenshot(
{
"url": "https://example.com",
"full_page": True,
"type": "webp",
}
)
Async Capture
import asyncio
import os
from screenshotapi import ScreenshotAPI
client = ScreenshotAPI(os.environ["SCREENSHOTAPI_KEY"])
async def main() -> None:
result = await client.async_screenshot({"url": "https://example.com"})
print(f"Duration: {result.metadata.duration_ms}ms")
await client.async_save({"url": "https://example.com"}, "screenshot.png")
asyncio.run(main())
Advanced Options
result = client.screenshot(
{
"url": "https://example.com/dashboard",
"width": 1280,
"height": 720,
"device_pixel_ratio": 2,
"full_page": False,
"type": "webp",
"quality": 85,
"color_scheme": "dark",
"wait_until": "networkidle0",
"wait_for_selector": ".ready",
"delay": 500,
"block_ads": True,
"remove_cookie_banners": True,
"remove_popups": True,
"remove_elements": [".newsletter", "#cookie-banner"],
"css_inject": "body { caret-color: transparent; }",
"js_inject": "window.scrollTo(0, 0)",
"stealth_mode": True,
"timezone": "America/New_York",
"locale": "en-US",
"cache_ttl": 3600,
"preload_fonts": True,
"geo_latitude": 40.7128,
"geo_longitude": -74.0060,
"geo_accuracy": 25,
}
)
HTML rendering uses POST /api/v1/screenshot automatically:
result = client.screenshot(
{
"html": "<html><body><h1>Invoice #123</h1></body></html>",
"type": "pdf",
}
)
Supported options:
| Python option | API parameter | Notes |
|---|---|---|
url |
url |
Required unless html is provided |
html |
html |
Raw HTML, sent with POST |
width, height |
width, height |
Viewport size |
full_page |
fullPage |
Capture full scrollable page |
type |
type |
png, jpeg, webp, or pdf |
quality |
quality |
JPEG/WebP quality, 1-100 |
color_scheme |
colorScheme |
light or dark |
wait_until |
waitUntil |
load, domcontentloaded, networkidle0, networkidle2 |
wait_for_selector |
waitForSelector |
CSS selector to wait for |
delay |
delay |
Extra delay in milliseconds |
block_ads |
blockAds |
Remove ads before capture |
remove_cookie_banners |
removeCookieBanners |
Remove common consent banners |
css_inject, js_inject |
cssInject, jsInject |
Inject CSS or JavaScript before capture |
stealth_mode |
stealthMode |
Enable anti-bot fingerprint masking |
device_pixel_ratio |
devicePixelRatio |
1, 2, or 3 |
timezone, locale |
timezone, locale |
Browser emulation settings |
cache_ttl |
cacheTtl |
Cache identical captures for N seconds |
preload_fonts |
preloadFonts |
Preload Google Fonts before capture |
remove_elements |
removeElements |
CSS selectors to remove |
remove_popups |
removePopups |
Remove common overlays and modals |
mockup_device |
mockupDevice |
browser, iphone, or macbook frame |
geo_latitude, geo_longitude, geo_accuracy |
geoLocation or geo query params |
Browser geolocation override |
Error Handling
from screenshotapi import (
AuthenticationError,
InsufficientCreditsError,
InvalidAPIKeyError,
NetworkError,
ScreenshotAPI,
ScreenshotAPIError,
ScreenshotFailedError,
)
client = ScreenshotAPI("sk_live_your_key_here")
try:
client.screenshot({"url": "https://example.com"})
except AuthenticationError:
print("Missing API key")
except InvalidAPIKeyError:
print("Invalid or revoked API key")
except InsufficientCreditsError as exc:
print(f"No credits remaining. Balance: {exc.balance}")
except ScreenshotFailedError as exc:
print(f"Screenshot failed: {exc}")
except NetworkError as exc:
print(f"Could not reach ScreenshotAPI: {exc}")
except ScreenshotAPIError as exc:
print(f"ScreenshotAPI error {exc.status} ({exc.code}): {exc}")
Examples
Runnable examples live in examples/:
script_usage.pyfor one-off scripts and cron jobsfastapi_app.pyfor FastAPI endpointsdjango_view.pyfor Django viewsflask_app.pyfor Flask routes
Pricing and Free Tier
ScreenshotAPI includes 200 free screenshots per month with no credit card required. Paid subscriptions and credit packs are available when you need more volume.
Links
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file screenshotapi_to-1.0.0.tar.gz.
File metadata
- Download URL: screenshotapi_to-1.0.0.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
695f7460a299333524885bda2da1767cf72d960c716962ee3d2986b437830395
|
|
| MD5 |
8bbc586c22fba9abe5da8f54a99b099a
|
|
| BLAKE2b-256 |
25f88f107cf1f341b8186483ba7e24418e46a648f957d98021db25156b741aab
|
Provenance
The following attestation bundles were made for screenshotapi_to-1.0.0.tar.gz:
Publisher:
publish.yml on miketromba/screenshotapi-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
screenshotapi_to-1.0.0.tar.gz -
Subject digest:
695f7460a299333524885bda2da1767cf72d960c716962ee3d2986b437830395 - Sigstore transparency entry: 2011395055
- Sigstore integration time:
-
Permalink:
miketromba/screenshotapi-python@fb5cc1ec84ec1035a71ead7e1fc962bc6e66f553 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/miketromba
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb5cc1ec84ec1035a71ead7e1fc962bc6e66f553 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file screenshotapi_to-1.0.0-py3-none-any.whl.
File metadata
- Download URL: screenshotapi_to-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05df5c0c92f6bdb8f838c555c78e7b4c98b53014a31860c13a5dd66b2a0b15b5
|
|
| MD5 |
2d5b852f239c3e0f48976c8fa87d1c42
|
|
| BLAKE2b-256 |
1bfd406dd415e5258125cc392ae7bd2e30bdf13dcd243749f42395620dfc5ef7
|
Provenance
The following attestation bundles were made for screenshotapi_to-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on miketromba/screenshotapi-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
screenshotapi_to-1.0.0-py3-none-any.whl -
Subject digest:
05df5c0c92f6bdb8f838c555c78e7b4c98b53014a31860c13a5dd66b2a0b15b5 - Sigstore transparency entry: 2011395135
- Sigstore integration time:
-
Permalink:
miketromba/screenshotapi-python@fb5cc1ec84ec1035a71ead7e1fc962bc6e66f553 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/miketromba
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fb5cc1ec84ec1035a71ead7e1fc962bc6e66f553 -
Trigger Event:
workflow_dispatch
-
Statement type: