Examples
HTML to an in-memory image buffer with Python and Puppeteer
Heads up before you start
Puppeteer has no official Python port. The community port, pyppeteer, is no longer maintained and bundles an old Chromium. These examples still work, but for new projects we recommend Playwright for Python — it covers everything Puppeteer does and is actively maintained.
Install the Python Puppeteer port and Chromium
pip install pyppeteer
pyppeteer-install Get the image as an in-memory buffer
import asyncio
from pyppeteer import launch
async def main():
browser = await launch()
page = await browser.newPage()
await page.setContent('<html><body><h1>Hello World</h1></body></html>')
image = await page.screenshot() # bytes, not written to disk
print(f'got {len(image)} bytes')
await browser.close()
asyncio.run(main()) Find out how to convert HTML to a base64 image with Python and Puppeteer.
That was 12 lines of code — plus a browser to run in production
Keeping headless browsers fed, patched and scaled is a job in itself. We built Urlbox so the same screenshot is one API call:
curl "https://api.urlbox.com/v1/YOUR_API_KEY/png?url=https://example.com" Try the Urlbox screenshot API — free trial, no browser babysitting.