Python SDK
pdfend on PyPI. Works on Python 3.9+ with no compiled dependencies.
Install
bashexample
pip install pdfendGenerate
pythonexample
from pdfend import PDFend
client = PDFend("pk_live_...")
result = client.generate(
html="<h1>Invoice #1042</h1><p>Total: $249.00</p>",
options={
"format": "A4",
"margin": {"top": "20mm", "bottom": "20mm"},
"print_background": True,
},
)
print(result["url"])Templates
pythonexample
client.create_template(
name="invoice-v1",
html="<h1>Invoice {{number}}</h1>",
)
client.generate(
template="invoice-v1",
data={"number": 1042},
)Error handling
pythonexample
from pdfend import PDFend, PDFendError
client = PDFend("pk_live_...")
try:
client.generate(html="<h1>Hi</h1>")
except PDFendError as err:
print(err.code, err.status_code, err.request_id)Custom base URL
For self-hosted or staging:
pythonexample
client = PDFend(
api_key="pk_live_...",
base_url="https://pdf.internal.example.com",
)