DEV Community

vesper_finch
vesper_finch

Posted on

I Replaced a $200/mo Screenshot API With a Single Python File

I was tired of paying $200/month for Browserless just to take screenshots. So I built my own.

The Problem

Every screenshot API service charges per-screenshot or per-month:

  • Browserless: $200-2000/mo
  • ScreenshotOne: $0.01/screenshot
  • Puppeteer self-hosted: Memory leaks, Docker headaches, scaling issues

All I needed was: URL in, PNG out.

The Solution: One Python File

SnapForge is a self-hosted screenshot and PDF API in a single Python file. No cloud, no subscriptions.

pip install playwright aiohttp
playwright install chromium
python snapforge.py
Enter fullscreen mode Exit fullscreen mode

API running on port 8787.

Usage

Screenshots

curl -X POST http://localhost:8787/screenshot \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://github.com", "full_page": true }' \
  --output github.png
Enter fullscreen mode Exit fullscreen mode

PDFs

curl -X POST http://localhost:8787/pdf \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com", "format": "A4" }' \
  --output page.pdf
Enter fullscreen mode Exit fullscreen mode

HTML to Image (invoices, OG images, reports)

{ "html": "<h1>Invoice #1234</h1><p>Total: 99 USD</p>", "width": 600 }
Enter fullscreen mode Exit fullscreen mode

Key Features

  • Device emulation: iPhone 14, iPad, Pixel 7, Desktop 4K
  • Element screenshots: Capture just a CSS selector
  • Dark mode: Test dark color scheme rendering
  • Concurrent pool: Multiple browser workers for parallel requests
  • API key auth: Protect your instance with Bearer tokens
  • Docker-ready: Single Dockerfile, one-line deployment

Docker

FROM python:3.11-slim
RUN pip install playwright aiohttp && playwright install chromium --with-deps
COPY snapforge.py /app/
WORKDIR /app
EXPOSE 8787
CMD ["python", "snapforge.py", "--workers", "4"]
Enter fullscreen mode Exit fullscreen mode

Use Cases

  • CI/CD visual regression testing
  • Invoice and report PDF generation
  • Dynamic OG image generation for social media
  • Dashboard monitoring screenshots
  • Documentation screenshot automation

The Math

10,000 screenshots/month:

  • ScreenshotOne: ~100 USD/mo
  • Browserless: 200+ USD/mo
  • SnapForge on a 5 USD VPS: 5 USD/mo

GitHub: github.com/vesper-astrena/snapforge

Single file. MIT license. Self-host and forget.

Top comments (0)