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.

Last updated

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.

FAQ

How do I convert HTML to PDF in Python without installing wkhtmltopdf?
POST the HTML to /v1/render with requests or httpx and write response.content to a file. There is no binary to install and no Chromium download — rendering happens server-side with WeasyPrint.
Does pdfrender have an official Python SDK?
No, deliberately. It is a single JSON endpoint, so requests or httpx is the whole integration — nothing to version, pin or keep up to date.
Should I use requests or httpx?
Either. Use httpx if you need async — the same POST works with AsyncClient, which matters when you render several documents concurrently.