I Replaced a $200/mo Screenshot API With a Single Python File
Source: Dev.to
Why I Built My Own Screenshot API
I was tired of paying $200/month for Browserless just to take screenshots. Existing services either charge per screenshot or have high monthly fees:
- Browserless: $200–$2000/mo
- ScreenshotOne: $0.01 per screenshot
- Puppeteer self‑hosted: memory leaks, Docker headaches, scaling issues
All I needed was a simple URL → PNG conversion.
Introducing SnapForge
SnapForge is a self‑hosted screenshot and PDF API that lives in a single Python file. No cloud, no subscriptions.
- MIT‑licensed, single‑file implementation
- Supports screenshots, PDFs, HTML rendering, device emulation, element capture, dark mode, and more
- Optional API‑key authentication
- Scalable with a concurrent worker pool
- Docker‑ready for one‑line deployment
Installation
pip install playwright aiohttp
playwright install chromiumRunning the API
python snapforge.pyThe service starts on port 8787.
API Usage
Screenshot
curl -X POST http://localhost:8787/screenshot \
-H "Content-Type: application/json" \
-d '{ "url": "https://github.com", "full_page": true }' \
--output github.pngPDF Generation
curl -X POST http://localhost:8787/pdf \
-H "Content-Type: application/json" \
-d '{ "url": "https://example.com", "format": "A4" }' \
--output page.pdfHTML Rendering (example payload)
{
"html": "\n## Invoice #1234\n\nTotal: 99 USD\n",
"width": 600
}Features
- Device emulation: iPhone 14, iPad, Pixel 7, Desktop 4K
- Element screenshots: capture a specific 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 Deployment
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"]Deploy with a single docker build and docker run command.
Common 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
Cost Comparison (10 000 screenshots/month)
| Service | Approx. Cost |
|---|---|
| ScreenshotOne | ~ $100 USD/mo |
| Browserless | $200+ USD/mo |
| SnapForge (5 USD VPS) | $5 USD/mo |
Repository
- GitHub: Single file, MIT license. Self‑host and forget.