Skip to main content

Looking for a maintained engine? playwright-snap is the Playwright-based successor to PyppeSnap, being built now. PyppeSnap keeps working, but it runs on Pyppeteer, which is no longer maintained: see Maintenance status.

PyppeSnap: give it a URL, a headless Chromium renders the page, and you get a PNG (str) or a PDF (bytes) back as base64

Test PyPI version Python versions License: MIT

PyppeSnap takes a snapshot of a web page and hands it to you as base64 text: a PNG of what fits in the browser window, or a PDF of the whole page. It opens the page in a headless Chromium (no window) through Pyppeteer, so JavaScript-heavy pages render like they do in a real browser. One function call, nothing written to disk: handy when the snapshot goes into JSON, a database, an email or an <img src="data:…">.

Maintenance status

PyppeSnap drives Chromium through Pyppeteer, and Pyppeteer is no longer maintained. Its last release, 2.0.0, came out in February 2024, and its own README now says the project is unmaintained and suggests Playwright instead. PyppeSnap stays on Pyppeteer, so here is what that means for you:

  • The browser is old and stays old. Pyppeteer downloads its own Chromium and never updates it: Chromium 117 (from 2023) with Pyppeteer 2.0.0, and Chromium 71 (from 2018) on Python 3.7, where pip can only install Pyppeteer 1.0.2. That Chromium misses years of security fixes, so only take snapshots of pages you trust, and don't put the web app example on the internet.
  • New web features may not render the way a current browser shows them.
  • Its dependencies are capped at old versions (websockets below 11, urllib3 below 2). Installing PyppeSnap can downgrade them, or clash with other packages in the same environment that need newer ones. A separate virtual environment avoids that.
  • Nobody fixes Pyppeteer any more. If a new Python release breaks it, PyppeSnap may not be able to fix that. CI takes real snapshots on Python 3.7 to 3.14 on every change, so a break shows up there first.

For new projects, have a look at playwright-snap, which uses Playwright, a browser library that is still maintained.

Installation

pip install pyppesnap

The package is called PyppeSnap on PyPI and is imported as pyppesnap. It works on Python 3.7–3.14.

The first snapshot downloads Chromium. Pyppeteer fetches its own Chromium build (about 100–200 MB) into your user folder the first time, so that call takes a while and needs internet access. Later calls take about a second.

On a minimal Linux image (for example python:3.12-slim in Docker) Chromium also needs some system libraries. On Debian/Ubuntu:

apt-get install -y libnss3 libatk1.0-0 libatk-bridge2.0-0 libcups2 libdrm2 libxkbcommon0 \
  libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libasound2 libpango-1.0-0 libcairo2

On Python 3.7, pip installs an older Pyppeteer (1.0.2) whose Chromium needs five more:

apt-get install -y libx11-xcb1 libxcursor1 libxtst6 libxss1 libgtk-3-0

If they are missing, the snapshot fails with Browser closed unexpectedly and a hint pointing here.

Quick start

from pyppesnap import get_image_snapshot_by_url, get_pdf_snapshot_by_url

png = get_image_snapshot_by_url('https://example.com')  # PNG as base64 str
pdf = get_pdf_snapshot_by_url('https://example.com')    # PDF as base64 bytes

print(png[:20])  # iVBORw0KGgoAAAANSUhE
print(pdf[:20])  # b'JVBERi0xLjQKJdPr6eEK'

Here is what the two functions return for the same page (real output, decoded):

The same page captured twice: get_image_snapshot_by_url returns a PNG of the 1600 x 900 browser window, get_pdf_snapshot_by_url returns a PDF of the whole page on a single sheet

API

Both functions take the same arguments: (url, width=1600, height=900, is_mobile=False).

Function Captures Returns
get_image_snapshot_by_url what fits in the width × height browser window PNG as base64 str
get_pdf_snapshot_by_url the whole page, laid out width pixels wide, on a single sheet PDF as base64 bytes

When a snapshot fails, both print the reason and return None.

  • url needs its scheme: https://example.com, not example.com.
  • width and height set the size of the browser window in CSS pixels.
  • is_mobile=True makes Chromium honour the page's mobile viewport tag. Pair it with a phone-sized window, for example width=390, height=844.
  • Each call starts its own Chromium and closes it again, even when something goes wrong.
  • A page gets 30 seconds to load, and a whole snapshot 120 seconds (the first-run Chromium download does not count). To change them, set pyppesnap.snapshot.NAVIGATION_TIMEOUT and pyppesnap.snapshot.SNAPSHOT_TIMEOUT (in seconds).
  • The functions are synchronous and also work where an event loop is already running, such as a Jupyter notebook. In async code, run them in a thread so they don't block your loop: png = await asyncio.to_thread(get_image_snapshot_by_url, url).

Save to a file or embed in HTML

import base64
from pyppesnap import get_image_snapshot_by_url, get_pdf_snapshot_by_url

with open('page.png', 'wb') as f:
    f.write(base64.b64decode(get_image_snapshot_by_url('https://example.com')))
with open('page.pdf', 'wb') as f:
    f.write(base64.b64decode(get_pdf_snapshot_by_url('https://example.com')))

# Or show the PNG straight in a web page:
html = '<img src="data:image/png;base64,{}">'.format(get_image_snapshot_by_url('https://example.com'))

Command line

Terminal: pyppesnap --url https://example.com prints the parameters and the PNG as base64; piping the PDF version through sed and base64 -d gives a valid one-page PDF

pyppesnap --url https://example.com              # PNG (the default, same as --type img)
pyppesnap --url https://example.com --type pdf   # PDF

Both types print plain base64 text on line 5, between the dashed lines, so you can save the file from the shell:

pyppesnap --url https://example.com --type pdf | sed -n 5p | base64 -d > example.pdf

The exit status is 0 when it worked, 1 when the snapshot failed (the reason is printed), and 2 when --url is missing or --type is not img or pdf.

Use it in a web app

example/ is a small Flask app: type a URL, press a button, and the server returns the snapshot, which the page shows as an image or an inline PDF.

pip install pyppesnap flask
cd example
python main.py   # then open http://127.0.0.1:9898

Don't put it on the internet as it is: it opens any URL a visitor types, including addresses inside your own network.

Development

pip install -e ".[test]"
pytest tests      # most tests use a fake browser; a few take real snapshots of example.com,
                  # so they need internet access and Chromium
tox -e py         # what CI runs: check-manifest + tests

The README images are made from the HTML files in docs/images/src/. take_demo_snapshots.py takes the real snapshots with PyppeSnap; each HTML file says how to render it.

License

MIT

Metadata

Release files for PyppeSnap 1.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for PyppeSnap 1.1.1
File Size Uploaded Provenance Actions
pyppesnap-1.1.1.tar.gz 21.8 kB Without provenance Details for pyppesnap-1.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for PyppeSnap 1.1.1
File Interpreter ABI Platform Actions
pyppesnap-1.1.1-py3-none-any.whl Python 3 none any Details for pyppesnap-1.1.1-py3-none-any.whl

Total release size: 32.7 kB

Release files / pyppesnap-1.1.1.tar.gz

Download URL pyppesnap-1.1.1.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e4488e58def4cd5e12834a5ff5a66b4038b2ea962131cc227cd074d97028811b
BLAKE2b-256 checksum
How to use checksums
fe08a44a244f8821dce68ca7c16bf08ddce1707c123f270def1fb42d64f20c48
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.1

Release files / pyppesnap-1.1.1-py3-none-any.whl

Download URL pyppesnap-1.1.1-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ce8bffe659cd52bcf5163595f0c17bd0b54c0d88d6297c35fb615e2cf3188fa3
BLAKE2b-256 checksum
How to use checksums
ffdb93945162db8d3cc74ed1fe2c7f7fde25574d28ecc10f1b1e91822b24686a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.15.1

Security for PyppeSnap 1.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page