explaingit

kozea/weasyprint

9,115PythonAudience · developerComplexity · 2/5LicenseSetup · easy

TLDR

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.

Mindmap

mindmap
  root((repo))
    What it does
      HTML to PDF
      CSS layout engine
      Paginated output
    Use cases
      Invoices
      Reports and tickets
      Web to print
    Tech details
      Python 3.10 plus
      CPython and PyPy
      No browser needed
    Audience
      Web developers
      Python app builders
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Generate PDF invoices or reports from HTML templates inside a Python web app.

USE CASE 2

Convert a styled HTML page to a printable PDF using the same CSS skills you already use for web design.

USE CASE 3

Automate PDF creation in a Django or Flask app without running a slow, heavyweight headless browser.

Tech stack

Python

Getting it running

Difficulty · easy Time to first run · 30min

Requires Python 3.10 or later.

BSD license, use freely for any purpose, including commercial use, as long as you keep the copyright notice.

In plain English

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.

Copy-paste prompts

Prompt 1
Show me how to use WeasyPrint in a Python script to convert an HTML file with CSS styles into a PDF.
Prompt 2
Help me generate a PDF invoice from a Jinja2 HTML template in a Flask app using WeasyPrint.
Prompt 3
Walk me through setting up WeasyPrint in a Django project so users can download their order history as a PDF.
Prompt 4
Help me style a multi-page WeasyPrint PDF with page numbers, a repeating header, and CSS print-specific rules.
Prompt 5
Show me how to convert an HTML string built in memory into a PDF using WeasyPrint in Python, without writing a temp file.
Open on GitHub → Explain another repo

← kozea on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.