WebSite2PDF¶
Render web pages and local HTML files to PDF, from Python or from the shell. Fully typed, async-capable, and driven by headless Chromium through Playwright.
from website2pdf import Client
with Client() as client:
client.convert("https://example.com", "example.pdf")
What it gives you¶
- One call per job.
convert()returnsbyteswhen you omit the destination and aPathwhen you give one, decided by typed overloads, so your editor and type checker both know which. - Concurrency that is real.
AsyncClientis asyncio-native and renders several pages at once in independent browser contexts sharing one browser process, rather than one browser per page. - Options you cannot typo. Three frozen dataclasses that validate on construction, instead of dictionaries with magic string keys.
- A browser that matches the library. Playwright ships a pinned Chromium build, so there is no driver to keep in step with a system browser.
- Type hints that survive installation. The package ships
py.typed.
Where to go next¶
- Installation: including the browser download step that is easy to miss.
- User guide: single pages, batches, waiting for content, cookies and headers.
- Command line: every flag, with examples.
- Options reference: every field of every option object.
- Migrating from 0.x: what changed and how to translate it.
- API reference: generated from the source.
Requirements¶
Python 3.10 or newer, on Linux, macOS or Windows. PDF rendering is Chromium-only: it is the only engine that exposes a print-to-PDF command.