Python PDF API
Add PDF generation and structured document extraction to FastAPI, Django, Flask, scripts, workers, and data pipelines.
Common Python workflows
FastAPI document endpoint
Receive application data, call PrefillPDF, and return or store the generated PDF.
PDF extraction worker
Process uploaded PDFs asynchronously, extract JSON, validate fields, and write results to a database.
Batch processing script
Read records from CSV or a database and generate or analyze documents in controlled batches.
How the integration works
Create an API client
Use requests, httpx, or your preferred HTTP client and load the API key from environment variables.
Prepare the request
Send JSON for PDF generation or multipart/file data for document extraction.
Validate the response
Check status codes, content type, returned JSON, and error fields.
Store or return the result
Save extracted data, stream the PDF, upload it to storage, or continue your business workflow.
Python request example
import os
import requests
response = requests.post(
"https://api.prefillpdf.com/fill-pdf",
headers={
"Authorization": f"Bearer {os.environ['PREFILLPDF_API_KEY']}",
"Accept": "application/json",
},
json={
"template_id": "your-template-id",
"data": {
"customer_name": "Jane Smith",
"amount": 25000,
},
},
timeout=60,
)
response.raise_for_status()
result = response.json()Benefits of using PrefillPDF with Python
FAQ
Do I need a dedicated Python SDK?
No. You can use requests, httpx, aiohttp, or another standard HTTP client.
Can I use PrefillPDF from FastAPI?
Yes. PrefillPDF can be called from FastAPI routes, service functions, and background workers.
Can extracted JSON be validated with Pydantic?
Yes. Map the extraction response into Pydantic models and apply your own validation rules.
Related integrations
Build your Python PDF workflow
Generate PDFs from structured data or extract structured JSON from existing documents with PrefillPDF.