Screenshot API with Python (2026)

Capture website screenshots from Python using the SnapAPI REST endpoint — with requests, httpx async, Django views, FastAPI endpoints, and Celery task patterns.

Pythonrequestshttpx DjangoFastAPIApril 2026

Quickstart (3 lines)

import requests

r = requests.post(
    "https://api.snapapi.pics/v1/screenshot",
    headers={"X-Api-Key": "YOUR_KEY"},
    json={"url": "https://example.com", "fullPage": True, "format": "png"},
)
open("screenshot.png", "wb").write(r.content)

requests: Sync Patterns

import requests
import os

API_KEY = os.environ["SNAPAPI_KEY"]
BASE_URL = "https://api.snapapi.pics/v1"

def screenshot(url: str, **options) -> bytes:
    """Capture a screenshot. Returns PNG/JPEG/WebP bytes."""
    r = requests.post(
        f"{BASE_URL}/screenshot",
        headers={"X-Api-Key": API_KEY},
        json={"url": url, **options},
        timeout=60,
    )
    r.raise_for_status()
    return r.content

# Full-page PNG
png = screenshot("https://example.com", fullPage=True)

# Mobile screenshot
mobile = screenshot(
    "https://example.com",
    device="iPhone 15 Pro",
    format="png",
)

# WebP with ad blocking
webp = screenshot(
    "https://example.com",
    format="webp",
    blockAds=True,
    blockCookieBanners=True,
    width=1440,
    height=900,
)

httpx: Async Batch Capture

import httpx
import asyncio

async def capture(client: httpx.AsyncClient, url: str, filename: str):
    r = await client.post(
        "https://api.snapapi.pics/v1/screenshot",
        headers={"X-Api-Key": os.environ["SNAPAPI_KEY"]},
        json={"url": url, "fullPage": True, "format": "png"},
        timeout=60,
    )
    r.raise_for_status()
    with open(filename, "wb") as f:
        f.write(r.content)
    print(f"✓ {filename}")

async def batch_capture(urls: list[dict]):
    async with httpx.AsyncClient() as client:
        tasks = [capture(client, item["url"], item["filename"]) for item in urls]
        await asyncio.gather(*tasks)   # all in parallel

# Usage
asyncio.run(batch_capture([
    {"url": "https://example.com",     "filename": "home.png"},
    {"url": "https://example.com/pricing", "filename": "pricing.png"},
    {"url": "https://example.com/blog",    "filename": "blog.png"},
]))

Django View: Screenshot on Request

# views.py
import requests
from django.http import HttpResponse, JsonResponse

def screenshot_view(request):
    url = request.GET.get("url")
    if not url:
        return JsonResponse({"error": "url required"}, status=400)

    r = requests.post(
        "https://api.snapapi.pics/v1/screenshot",
        headers={"X-Api-Key": settings.SNAPAPI_KEY},
        json={"url": url, "fullPage": True},
        timeout=60,
    )

    if not r.ok:
        return JsonResponse({"error": "capture failed"}, status=500)

    return HttpResponse(r.content, content_type="image/png")

FastAPI: Async Screenshot Endpoint

from fastapi import FastAPI, HTTPException
from fastapi.responses import Response
import httpx
import os

app = FastAPI()
client = httpx.AsyncClient()

@app.get("/screenshot")
async def screenshot(url: str, full_page: bool = True):
    r = await client.post(
        "https://api.snapapi.pics/v1/screenshot",
        headers={"X-Api-Key": os.environ["SNAPAPI_KEY"]},
        json={"url": url, "fullPage": full_page, "format": "png"},
        timeout=60,
    )
    if not r.is_success:
        raise HTTPException(status_code=502, detail="Screenshot capture failed")
    return Response(content=r.content, media_type="image/png")

Celery: Background Screenshot Task

# tasks.py
from celery import shared_task
import requests, boto3, os

s3 = boto3.client("s3")

@shared_task(bind=True, max_retries=3, default_retry_delay=10)
def capture_and_store(self, url: str, s3_key: str):
    """Capture screenshot and upload to S3."""
    try:
        r = requests.post(
            "https://api.snapapi.pics/v1/screenshot",
            headers={"X-Api-Key": os.environ["SNAPAPI_KEY"]},
            json={"url": url, "fullPage": True},
            timeout=60,
        )
        r.raise_for_status()
        s3.put_object(
            Bucket=os.environ["S3_BUCKET"],
            Key=s3_key,
            Body=r.content,
            ContentType="image/png",
        )
        return {"status": "ok", "key": s3_key}
    except Exception as exc:
        raise self.retry(exc=exc)
SnapAPI free tier: 200 captures/month. Python SDK and OpenAPI spec available at snapapi.pics/docs. Get your free API key →