HTML to PDF in Python
Generate PDFs from HTML in Python with requests or httpx — one POST, no browser or wkhtmltopdf binary to install. Copy-paste example inside.
No headless browser, no wkhtmltopdf binary, no native
dependencies — rendering is one HTTP call with whatever client you already
use. With requests:
import requests
resp = requests.post(
"https://api.pdfrender.dev/v1/render",
json={"html": "<h1>Report</h1><p>Generated in Python.</p>",
"filename": "report.pdf"},
headers={"X-API-Key": "YOUR_KEY"}, # optional — anonymous works too
timeout=30,
)
resp.raise_for_status()
with open("report.pdf", "wb") as f:
f.write(resp.content)
httpx (sync or async) is identical apart from the import. A 4xx response
is JSON whose detail starts with a stable error code (for example
html_too_large or external_resource_blocked) — see the
error-code guide.
Building the HTML
Render any template engine's output. A common pattern is Jinja2 → HTML → PDF:
from jinja2 import Template
html = Template(open("invoice.html").read()).render(
number="2026-001", total="240.00 €"
)
Then POST html as above. Style with plain CSS — including @page rules for
page size and
headers/footers.
Try it free
Try it free — 100 renders a month, no card — or test your HTML first in the free browser tool.