Website screenshots & PDFs in Python

Skip installing Selenium or Playwright and a browser on your server. With requests you get a PNG or PDF back from one call.

1. Get an API key

Click Get free key. You get 25 free renders a month instantly, no account needed. Store the key in an environment variable called SHOTMINT_KEY.

2. Screenshot a URL

import os, requests

r = requests.get(
    "https://shotmint.creasework.com/v1/screenshot",
    params={"url": "https://example.com", "full_page": "true", "device_scale_factor": 2},
    headers={"X-API-Key": os.environ["SHOTMINT_KEY"]},
    timeout=60,
)
r.raise_for_status()
with open("shot.png", "wb") as f:
    f.write(r.content)
print("credits left:", r.headers.get("X-Credits-Remaining"))

Useful parameters: full_page=true for the whole scrollable page, width/height for the viewport, device_scale_factor=2 for retina, selector to capture a single element, dark_mode=true, and hide_selectors to remove cookie banners. See the full list.

3. Turn HTML into a PDF

html = "<h1>Report</h1><p>Generated by Django</p>"
r = requests.post(
    "https://shotmint.creasework.com/v1/pdf",
    json={"html": html, "format": "Letter", "landscape": True},
    headers={"X-API-Key": os.environ["SHOTMINT_KEY"]},
    timeout=60,
)
open("report.pdf", "wb").write(r.content)

PDF options include format (A4, Letter…), landscape, margin, and print_background. You can pass a url instead of html.

Errors & credits

A failed render never costs a credit. Status 400 means bad input or an unreachable URL, 402 means you're out of credits, and 429/503 mean you should retry with backoff. Every successful response includes an X-Credits-Remaining header, and screenshots and PDFs of a URL also carry X-Page-Status: the HTTP status the site answered with. A 403 there usually means you captured the site's bot-protection page, a 404 its error page.

Notes for Python

In Django or Flask, render a template to a string (render_to_string / render_template) and send that as html. Fonts and CSS load just like in Chrome, so you don't have to deal with WeasyPrint or wkhtmltopdf quirks.

Production version: retries, timeouts and page status

The quickstart above stops at the first error. In production you want three more things: retry only the failures that can fix themselves (503 when the renderer is busy, network timeouts), never retry a 400 or 402, and warn when the site itself answered with an error page. This script does all three for screenshots and PDFs, and prints the credits left after each call:

import os
import time

import requests

API = "https://shotmint.creasework.com"
session = requests.Session()
session.headers["X-API-Key"] = os.environ["SHOTMINT_KEY"]


def render(path, params, attempts=3):
    """Retries only what is worth retrying: 503 (renderer busy) and network errors.
    A 400 (bad input, unreachable site) or 402 (no credits) will not fix itself."""
    for i in range(attempts):
        try:
            res = session.post(API + path, json=params, timeout=(10, 90))
        except (requests.ConnectionError, requests.Timeout):
            if i == attempts - 1:
                raise
            time.sleep(2 ** i)
            continue
        if res.ok:
            page = int(res.headers.get("X-Page-Status", 0))
            if page >= 400:
                print(f"site answered {page}: you may have captured an error or bot page")
            print("credits left:", res.headers.get("X-Credits-Remaining"))
            return res.content
        if res.status_code != 503:
            try:
                msg = res.json()["error"]
            except ValueError:
                msg = res.text
            raise RuntimeError(f"{res.status_code}: {msg}")
        time.sleep(2 ** i)
    raise RuntimeError(f"renderer still busy after {attempts} attempts")


shot = render("/v1/screenshot", {"url": "https://docs.python.org/3/tutorial/index.html", "full_page": True, "format": "png"})
with open("shot.png", "wb") as f:  # open the file only after the render succeeded
    f.write(shot)
pdf = render("/v1/pdf", {"url": "https://example.com", "format": "A4"})
with open("page.pdf", "wb") as f:
    f.write(pdf)

requests waits forever unless you pass timeout; (10, 90) means 10 s to connect and 90 s for the response. Call render() before open(..., "wb"): opening first truncates the file, so a failed render left an empty shot.png behind in our first draft. A Session reuses the TLS connection across renders.

Timing, measured on 2026-10-25: a full-page capture of a long Wikipedia article plus an A4 PDF took 8.5 to 25 s end to end, so keep the read timeout well above 30 s. Full-page captures are capped at 16,000 px tall (the Go and PHP articles hit that cap). With a format the API doesn't support, the script stops at once with the API's own message: 400: format must be png, jpeg or webp (got "gif").

Prefer a client library?

The zero-dependency Shotmint Python SDK wraps these calls: screenshot() and pdf() return the bytes with the credits left attached, and errors raise with the HTTP status. Install it straight from our domain, no registry account needed.

Try it with 25 free renders a month

No signup, no card. Get a key in one click, then buy credits only if you need more (from €5 for 2,000, never expire). From a script, an AI agent, Make or Zapier, POST /v1/keys/free (no body) returns a key as JSON (openapi.json, no-code recipes).

Get a free API key Full API reference

More guides: API quickstarts by language

All guides: guides · integrations · comparisons