Python SDK

Python HTML to PDF, no system dependencies

The usual Python HTML-to-PDF route wants cairo, pango, and their headers installed. Forme doesn't. pip install formepdf[local] pulls a single dependency and renders in-process — the same engine the JavaScript packages run.

MIT licensed, Python 3.8+.

invoice.py
from jinja2 import Template
from formepdf import render_html

# The HTML you already have — a Jinja template + your data.
html = Template(INVOICE_HTML).render(invoice=invoice)

# Same Rust engine as @formepdf/html, run in-process via wasmtime.
pdf = render_html(html, page_size="A4")
open("invoice.pdf", "wb").write(pdf)

1 dependency: wasmtime. No cairo, no pango, no browser.

Byte-identical output to the JavaScript engine, checked in CI.

Anywhere slim containers, Lambda, and Windows.

Why this path

What makes it different

The same engine — and a test that proves it

Not a re-implementation. The Python path runs the identical Rust engine as @formepdf/html, compiled to wasm32-wasip1. A CI job renders the same input through both and requires identical bytes on every commit, including the PDF/A-2b-with-embedded-fonts case.

No system libraries

pip install formepdf[local] pulls one dependency (wasmtime) and runs in slim containers, on Lambda, and on Windows — the places a native-library toolchain makes painful.

Conformance, not just rendering

Tagged PDFs, PDF/UA accessibility, and the PDF/A archival ladder through the same engine paths — pass pdf_ua=True or pdfa="2b" with an embeddable font. Local certify_pdf signs with PKCS#7 / X.509.

Or write components

Prefer objects to markup? The component DSL — Document, Page, View, Text, Image, tables with repeating headers, charts, QR and barcodes, form fields — builds the same documents in pure Python.

Not on the local Python path yet: redact, merge, and extract. Everything above is.

In a web app

Return a PDF from Django or Flask

Render the template you already have, then return the bytes. No subprocess, no temporary files.

  • Works with Jinja2 and Django templates
  • Print CSS: @page rules, margin boxes, page counters
  • Warnings name any unsupported CSS
views.py
from django.http import HttpResponse
from django.template.loader import render_to_string
from formepdf import render_html

def invoice_pdf(request, pk):
    html = render_to_string("invoice.html", {"invoice": get_invoice(pk)})
    pdf = render_html(html, page_size="A4")
    return HttpResponse(pdf, content_type="application/pdf")

Python HTML to PDF questions

Can I generate PDFs from Python without system dependencies?
Yes. pip install formepdf[local] renders HTML and print CSS to PDF in-process through the engine compiled to wasm32-wasip1 and run via wasmtime — no cairo, no pango, no system libraries, no browser. It pulls a single dependency.
Is the Python output the same as the JavaScript output?
Yes. It is the same Rust engine, and a CI job renders the same input through both and requires byte-identical output on every commit, including PDF/A with embedded fonts.
Can Python produce PDF/A and accessible PDFs?
Yes. Pass pdfa="2b" or pdf_ua=True with an embeddable font. Local certify_pdf signs with PKCS#7 and X.509.
What is not available in Python yet?
Redact, merge, and extract are bound in the JavaScript packages but not yet on the local Python path.