HTML to PDF in Python without the headaches
One pip install docapi-sdk. No system packages, no wkhtmltopdf binary, no WeasyPrint C dependencies. Works in Django, Flask, FastAPI, and any Python 3.8+ environment.
Free tier: 100 PDFs/month. No credit card required.
Install and generate your first PDF
The DocAPI Python SDK has zero dependencies and ships as a single pure-Python package. No C extensions, no system libraries, no binary blobs. It works anywhere Python runs — including AWS Lambda, Google Cloud Functions, and Docker containers.
- pip install docapi-sdk — that's the only step
- Python 3.8+ supported, zero third-party deps
- Full A4 / Letter / custom page size support
- Print background colors and images by default
- Returns raw bytes — stream directly to response or disk
- Automatic retry on transient errors
from docapi import DocAPI
client = DocAPI("pk_live_...")
pdf = client.pdf("<h1>Hello World</h1>", format="A4")
with open("output.pdf", "wb") as f:
f.write(pdf)Works with your existing Python framework
Drop DocAPI into Django, Flask, or any other framework with a few lines of code.
Django view
Render a template and stream as PDF
from django.http import HttpResponse
from django.template.loader import render_to_string
from docapi import DocAPI
import os
client = DocAPI(os.environ["DOCAPI_KEY"])
def invoice_view(request, pk):
invoice = Invoice.objects.get(pk=pk)
html = render_to_string("invoice.html", {"invoice": invoice})
pdf = client.pdf(html, format="A4")
return HttpResponse(
pdf,
content_type="application/pdf",
headers={
"Content-Disposition": f'inline; filename="invoice-{pk}.pdf"'
},
)Flask route
Return a PDF directly from a route
from flask import Flask, send_file
from docapi import DocAPI
import io, os
app = Flask(__name__)
client = DocAPI(os.environ["DOCAPI_KEY"])
@app.route("/invoice/<int:pk>.pdf")
def invoice_pdf(pk):
html = build_invoice_html(pk)
pdf = client.pdf(html)
return send_file(
io.BytesIO(pdf),
mimetype="application/pdf",
download_name=f"invoice-{pk}.pdf",
)import requests
response = requests.post(
"https://api.docapi.co/v1/pdf",
headers={
"x-api-key": "pk_live_...",
"Content-Type": "application/json",
},
json={
"html": "<h1>Hello World</h1>",
"options": {"format": "A4", "printBackground": True},
},
)
with open("output.pdf", "wb") as f:
f.write(response.content)Prefer raw HTTP? Use requests directly.
The API is a simple REST endpoint. If you would rather not add another package, call it directly with requests or Python's built-in urllib. The SDK is just a thin convenience wrapper around the same HTTP call.
- POST https://api.docapi.co/v1/pdf
- x-api-key header for authentication
- JSON body with html and options fields
- Response body is raw PDF bytes
- Same API key for PDFs and screenshots
Common Python PDF use cases
Invoice generation
Render your Jinja2 invoice template and return a PDF response from your Django or Flask view. Triggered on every order confirmation.
Report exports
Export data reports and dashboards as shareable PDFs. Query your database, render to HTML, and stream the PDF to the browser.
E-signature documents
Generate agreement or contract PDFs from templates with customer-specific data, ready to be sent for signing via DocuSign or similar.
Shipping labels & receipts
Produce thermal-printer-ready or standard PDF shipping labels and packing slips from order data in your Python backend.
Statement generation
Monthly account statements, bank-style PDFs, and financial summaries generated server-side from your data warehouse.
Content archiving
Scrape or export web content as persistent PDF archives. Useful for compliance workflows, legal discovery, and long-term record-keeping.
vs. WeasyPrint, pdfkit, and ReportLab
Other Python PDF libraries require heavy system dependencies or force you to learn a new API.
| Feature | DocAPI | WeasyPrint | pdfkit | ReportLab |
|---|---|---|---|---|
| Zero system deps | ✓ | Requires Cairo, Pango | Requires wkhtmltopdf | ✓ |
| pip install only | ✓ | ✗ | ✗ | ✓ |
| Full CSS support | ✓ | Partial | ✓ | ✗ |
| Works in Lambda | ✓ | Complex layer | ✗ | ✓ |
| Rendered by Chromium | ✓ | ✗ | ✓ (old) | ✗ |
| Django/Flask ready | ✓ | ✓ | ✓ | Complex |
| Free tier | 100/mo | Self-hosted | Self-hosted | Self-hosted |
Simple, predictable pricing
Start free, scale when you need to. No credit card required to get started.
Free
$0/mo
100 PDFs/month
Starter
$19/mo
1,000 PDFs/month
Pro
$49/mo
5,000 PDFs/month
Business
$99/mo
20,000 PDFs/month