WeasyPrint
The awesome document factory
WeasyPrint is a Python library that converts HTML and CSS into PDFs, great for generating invoices, reports, and tickets from web templates without needing a full browser or a separate document-layout tool.
WeasyPrint is a Python library that converts HTML and CSS into PDF files. If you know how to build a web page, you already know how to describe a document for WeasyPrint: write the content in HTML, style it with CSS, and hand it to the library to produce a finished PDF. The project is free to use under a BSD license.
The main use cases are things like invoices, reports, tickets, and other documents that need consistent formatting across many pages. Web designers often find this appealing because they can apply the same CSS skills they already use, rather than learning a separate document-layout tool or dealing with word processor export quirks.
Under the hood, WeasyPrint does not rely on a full browser engine like the ones powering Chrome or Firefox. Instead, it has its own CSS layout engine written in Python, built specifically for paginated output. This makes it smaller and easier to modify than a full browser, but it also means it supports a focused subset of CSS aimed at printing, not every feature a browser handles.
The library requires Python 3.10 or later and works on both CPython (the standard Python runtime) and PyPy. It is developed and maintained by CourtBouillon, a company that also offers professional support and maintenance contracts for organizations that need reliability guarantees.
Documentation and working examples are hosted on the project's own website, and the code, issue tracker, and releases all live on GitHub. If you need to generate PDFs programmatically from HTML templates, this library is a direct way to do it without a headless browser.
Where it fits
- Generate PDF invoices or reports from HTML templates inside a Python web app.
- Convert a styled HTML page to a printable PDF using the same CSS skills you already use for web design.
- Automate PDF creation in a Django or Flask app without running a slow, heavyweight headless browser.