Menu
pythonautomationtutorial

How to Automate Screenshots with Python and SnapSharp

SnapSharp Team·March 5, 2026·7 min read

Automate Screenshots with Python

Whether you're monitoring websites, generating reports, or building a scraping pipeline, automated screenshots save hours of manual work. Here's how to do it cleanly with Python.

Setup

The fastest way is the official Python SDK:

pip install snapsharp

Set your API key as an environment variable:

export SNAPSHARP_API_KEY=sk_live_your_key_here

Basic screenshot (SDK)

from snapsharp import SnapSharp
import os

snap = SnapSharp(os.environ["SNAPSHARP_API_KEY"])

image = snap.screenshot("https://example.com", width=1280, height=720)
with open("example.png", "wb") as f:
    f.write(image)

That's it — one function call. The SDK handles authentication, error types, and retries.

Without the SDK (raw requests)

If you prefer raw HTTP, use requests:

pip install requests
import os
import requests

API_KEY = os.environ["SNAPSHARP_API_KEY"]
BASE_URL = "https://api.snapsharp.dev/v1"

def screenshot(url: str, output_path: str, **kwargs) -> None:
    params = {"url": url, "width": 1280, "height": 720, **kwargs}
    response = requests.get(
        f"{BASE_URL}/screenshot",
        params=params,
        headers={"Authorization": f"Bearer {API_KEY}"},
    )
    response.raise_for_status()
    with open(output_path, "wb") as f:
        f.write(response.content)
    print(f"Saved: {output_path} ({len(response.content) // 1024}KB)")

screenshot("https://example.com", "example.png")

Screenshot multiple URLs

import concurrent.futures

URLS = [
    ("https://example.com", "example.png"),
    ("https://github.com", "github.png"),
    ("https://linear.app", "linear.png"),
]

def capture(args: tuple[str, str]) -> str:
    url, path = args
    screenshot(url, path)
    return path

with concurrent.futures.ThreadPoolExecutor(max_workers=3) as executor:
    results = list(executor.map(capture, URLS))

Full-page screenshot with dark mode

screenshot(
    "https://docs.example.com",
    "docs-dark-full.png",
    full_page=True,
    dark_mode=True,
    format="jpeg",
    quality=85,
)

Screenshot with authentication cookies

import json

screenshot(
    "https://app.example.com/dashboard",
    "dashboard.png",
    cookies=json.dumps([
        {"name": "session", "value": "your_session_value", "domain": "app.example.com"}
    ]),
    width=1440,
    height=900,
)

Daily monitoring script

import os
import requests
from datetime import datetime
from pathlib import Path

def daily_monitor(urls: list[str], output_dir: str = "screenshots") -> None:
    date_str = datetime.now().strftime("%Y-%m-%d")
    output_path = Path(output_dir) / date_str
    output_path.mkdir(parents=True, exist_ok=True)

    for url in urls:
        domain = url.split("//")[1].split("/")[0]
        filename = output_path / f"{domain}.png"

        try:
            screenshot(url, str(filename), cache=False)
        except requests.HTTPError as e:
            print(f"Failed {url}: {e}")

SITES_TO_MONITOR = [
    "https://yourapp.com",
    "https://yourapp.com/pricing",
    "https://yourapp.com/dashboard",
]

daily_monitor(SITES_TO_MONITOR)

Handle rate limits

The API returns 429 when rate limits are hit. Handle it gracefully:

import time

def screenshot_with_retry(url: str, output: str, max_retries: int = 3) -> None:
    for attempt in range(max_retries):
        response = requests.get(
            f"{BASE_URL}/screenshot",
            params={"url": url},
            headers={"Authorization": f"Bearer {API_KEY}"},
        )
        if response.status_code == 429:
            retry_after = int(response.headers.get("Retry-After", 30))
            print(f"Rate limited. Waiting {retry_after}s...")
            time.sleep(retry_after)
            continue
        response.raise_for_status()
        with open(output, "wb") as f:
            f.write(response.content)
        return
    raise RuntimeError("Max retries exceeded")

Using the SDK for error handling

The SDK provides typed exceptions for cleaner error handling:

from snapsharp import SnapSharp, AuthError, RateLimitError, TimeoutError

snap = SnapSharp(os.environ["SNAPSHARP_API_KEY"])

try:
    image = snap.screenshot("https://example.com")
except AuthError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")
except TimeoutError:
    print("Screenshot timed out")

See the full SDK documentation at snapsharp.dev/docs/sdks.

That's it. A few lines of Python, and you have a full screenshot automation pipeline.