Allscreenshots Docs
SDKs

Python SDK

Python SDK with sync and async support

Python SDK

The official Python SDK for the AllScreenshots API with synchronous and asynchronous client support.

Source code: GitHub | Package: allscreenshots-sdk

Installation

pip install allscreenshots-sdk
# or
uv add allscreenshots-sdk

Quick start

from allscreenshots_sdk import AllscreenshotsClient

client = AllscreenshotsClient.builder().build()

image_bytes = client.screenshots.capture("https://example.com")

with open("screenshot.png", "wb") as f:
    f.write(image_bytes)

client.close()

Configuration

Builder pattern

client = (
    AllscreenshotsClient.builder()
    .with_api_key("your-api-key")
    .with_base_url("https://api.allscreenshots.com")
    .with_timeout(60)
    .with_max_retries(3)
    .build()
)

Environment variables

Set ALLSCREENSHOTS_API_KEY to automatically configure authentication:

# Client will read API key from environment
client = AllscreenshotsClient.builder().build()

Context manager

with AllscreenshotsClient.builder().with_api_key("your-api-key").build() as client:
    image = client.screenshots.capture("https://example.com", device="Desktop HD")
    with open("screenshot.png", "wb") as f:
        f.write(image)

Async client

import asyncio
from allscreenshots_sdk import AllscreenshotsClient

async def main():
    async with AllscreenshotsClient.builder().with_api_key("your-api-key").build_async() as client:
        image = await client.screenshots.capture("https://example.com")
        with open("screenshot.png", "wb") as f:
            f.write(image)

asyncio.run(main())

Capture screenshots

Basic capture

image_bytes = client.screenshots.capture("https://example.com")

with open("screenshot.png", "wb") as f:
    f.write(image_bytes)

With options

image = client.screenshots.capture(
    "https://example.com",
    device="Desktop HD",
    format="png",
    full_page=True,
    dark_mode=True,
    block_ads=True,
    block_cookie_banners=True,
    delay=1000,
)

Device presets

# Desktop
desktop = client.screenshots.capture("https://example.com", device="Desktop HD")

# Mobile
mobile = client.screenshots.capture("https://example.com", device="iPhone 15")

# Tablet
tablet = client.screenshots.capture("https://example.com", device="iPad Pro 11")

Async jobs

For long-running captures:

# Create async job
job = client.screenshots.capture_async("https://example.com", full_page=True)

print(f"Job ID: {job.job_id}")

# Poll for completion
result = client.jobs.get(job.job_id)

if result.status == "completed":
    image_data = client.jobs.get_result(job.job_id)
    with open("screenshot.png", "wb") as f:
        f.write(image_data)

Bulk capture

Process multiple URLs efficiently:

bulk_job = client.bulk.create(
    urls=[
        {"url": "https://example1.com"},
        {"url": "https://example2.com"},
        {"url": "https://example3.com"},
    ],
    defaults={
        "device": "Desktop HD",
        "format": "png",
    },
)

# Check status
status = client.bulk.get(bulk_job.bulk_job_id)

Composition

Combine multiple screenshots into a single image:

composed = client.screenshots.compose(
    url="https://example.com",
    variants=[
        {"device": "Desktop HD", "label": "Desktop"},
        {"device": "iPhone 15", "label": "Mobile"},
    ],
    output={
        "layout": "HORIZONTAL",
        "spacing": 20,
    },
)

Available layouts: GRID, HORIZONTAL, VERTICAL, MASONRY, MONDRIAN

Schedules

Create recurring screenshot captures:

# Create a schedule
schedule = client.schedules.create(
    name="Daily Homepage",
    url="https://example.com",
    schedule="0 9 * * *",
    timezone="America/New_York",
)

# List schedules
schedules = client.schedules.list()

# Get captures
captures = client.schedules.get_captures(schedule.schedule_id)

Usage tracking

Monitor your API usage:

usage = client.usage.get()
print(f"Screenshots: {usage.screenshot_count}/{usage.quota}")

Error handling

from allscreenshots_sdk import (
    AllscreenshotsError,
    AuthenticationError,
    ValidationError,
    RateLimitError,
    NotFoundException,
    ServerError,
)

try:
    screenshot = client.screenshots.capture("https://example.com")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except AuthenticationError:
    print("Invalid API key")
except ValidationError as e:
    print(f"Validation error: {e.message}")
except AllscreenshotsError as e:
    print(f"API error: {e.message}")

License

Apache License 2.0

On this page