Skip to content

Python Screenshot API: End-to-End Example

A complete Python tutorial covering installation, basic screenshots, PDF generation, automation steps, data extraction, and batch processing with the ScreenshotCenter SDK.

Installation

Install the Python SDK from PyPI:

pip install screenshotcenter

Basic screenshot

import screenshotcenter

client = screenshotcenter.Client(api_key="YOUR_API_KEY")

# Take a screenshot
result = client.create(url="https://example.com")
print(result["screenshot_url"])

The create() method sends the request and returns when the screenshot is ready. The result includes the screenshot URL, status, and metadata.

Full-page screenshot with viewport control

result = client.create(
    url="https://example.com",
    full_page=True,
    screen_width=1920,
    screen_height=1080,
    device_scale=2,  # Retina
    delay=2000,      # Wait 2s for lazy content
)

PDF generation

result = client.create(
    url="https://example.com/invoice",
    pdf=True,
    pdf_format="A4",
    pdf_margin_top="20mm",
    pdf_margin_bottom="20mm",
    pdf_background=True,
)

# Download the PDF
client.download(result["id"], "invoice.pdf")

See PDF generation API for all PDF parameters.

Automation steps (login flow)

result = client.create(
    url="https://app.example.com/login",
    steps=[
        {"action": "type", "target": "#email", "value": "user@example.com"},
        {"action": "type", "target": "#password", "value": "s3cret"},
        {"action": "click", "target": "button[type=submit]"},
        {"action": "wait", "value": 3000},
    ],
)

The browser fills the login form, submits it, waits for the page to load, then takes the screenshot. See authenticated screenshot API for more patterns.

Data extraction with trackers

result = client.create(
    url="https://example.com/product/123",
    trackers=[
        {"name": "price", "selector": ".product-price", "type": "text"},
        {"name": "title", "selector": "h1", "type": "text"},
        {"name": "in_stock", "selector": ".stock-status", "type": "text"},
    ],
)

# Access extracted data
for tracker in result.get("trackers", []):
    print(f"{tracker['name']}: {tracker['value']}")

Trackers extract DOM values alongside the screenshot — no separate scraping step needed. See web page data extraction for advanced patterns.

Country routing

# Capture from Germany
result = client.create(
    url="https://example.com",
    country="de",
    locale="de-DE",
    timezone="Europe/Berlin",
)

Batch screenshots

# Submit a batch job
batch = client.batch_create(
    urls=["https://example.com/page1", "https://example.com/page2", "https://example.com/page3"],
    options={"full_page": True, "country": "us"},
)

# Poll for completion
info = client.batch_info(batch["id"])
print(f"Progress: {info['completed']}/{info['total']}")

For large-scale batch processing, see batch screenshots at scale.

Delivering to S3

result = client.create(
    url="https://example.com",
    apps=[{
        "app": "s3",
        "bucket": "my-screenshots",
        "path": "captures/{yyyy}/{mm}/{dd}/{id}.png",
    }],
)

See S3 integration for IAM setup and path template variables.

Error handling

try:
    result = client.create(url="https://example.com")
except screenshotcenter.APIError as e:
    print(f"API error {e.status_code}: {e.message}")
except screenshotcenter.TimeoutError:
    print("Screenshot timed out — try increasing delay")

Next steps

Browse the full Python SDK reference for all methods and parameters. For JavaScript, see the JavaScript SDK.