The official Python SDK for the PDFBridge API. Generate pixel-perfect PDFs from HTML/URLs.
Project description
pdfbridge-python
The official Python SDK for the PDFBridge API. Generate pixel-perfect PDFs from HTML or URLs.
Features
- Typed Inputs & Outputs: Fully powered by Pydantic V2 for strict runtime validation and autocomplete.
- Convenient Sync Methods: Out-of-the-box
generate_and_waitblocking wrapper so you don't have to write your own pollers. - Ghost Mode Native: Fetch raw PDF bytes directly into memory. No intermediate storage or URLs.
- Bulk Conversions: Convert up to 1,000 documents simultaneously.
Installation
pip install pdfbridge-python
Quick Start
import os
from pdfbridge import PDFBridge
# Initialize with your secret API key
# Can also be picked up automatically via the PDFBRIDGE_API_KEY environment variable.
client = PDFBridge(api_key="pk_live_your_key_here")
# Generate and wait for completion (blocks execution until PDF is ready)
status = client.generate_and_wait(
url="https://github.com",
filename="github_page.pdf",
options={
"format": "A4",
"printBackground": True
}
)
print(f"Success! Download PDF from: {status.pdfUrl}")
Advanced Usage
👻 Ghost Mode (Memory-Native)
Ghost Mode returns the direct bytes of the generated PDF without saving it to Cloud Storage. This is perfect for securely piping documents to your own S3 bucket or streaming directly to users.
# Returns raw bytes natively
pdf_bytes = client.generate(
html="<h1>Highly Confidential Financial Data</h1>",
ghostMode=True,
options={
"format": "Letter",
"margin": "1in"
}
)
with open("secure_report.pdf", "wb") as f:
f.write(pdf_bytes)
🚀 Bulk Generation
Queue up to 1,000 PDF generation jobs natively in a single API call.
bulk_job = client.generate_bulk(
webhookUrl="https://api.yourdomain.com/webhooks/pdfbridge",
jobs=[
{"url": "https://example.com/invoice/123", "filename": "INV-123.pdf"},
{"url": "https://example.com/invoice/124", "filename": "INV-124.pdf"},
{"url": "https://example.com/invoice/125", "filename": "INV-125.pdf"}
]
)
print(f"Queued {len(bulk_job.jobs)} items.")
🧠 Templates & Variables
Pass dynamic data into your saved HTML templates.
client.generate_and_wait(
templateId="tmpl_987654321",
variables={
"customer_name": "Jane Doe",
"total_amount": "$45.00"
}
)
Error Handling
The SDK raises PDFBridgeError on any HTTP failures, authentication issues, or data malformations.
from pdfbridge import PDFBridgeError
try:
client.generate(url="invalid-url")
except PDFBridgeError as e:
print(f"API Failed with status {e.status_code}: {str(e)}")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pdfbridge_python-1.1.0.tar.gz.
File metadata
- Download URL: pdfbridge_python-1.1.0.tar.gz
- Upload date:
- Size: 9.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c7825f2749f6ea94e53a13bf3278a58a0432143e4a0ee1e0e4026c6c04bdd42b
|
|
| MD5 |
8926e3b1badcd7e87ff6f4d673c8e46c
|
|
| BLAKE2b-256 |
1d65325a5db8ab7dafd57d6fca296ef62fa444e839281b496dd48c1f7b943156
|
File details
Details for the file pdfbridge_python-1.1.0-py3-none-any.whl.
File metadata
- Download URL: pdfbridge_python-1.1.0-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32d04e00997a0a94df5cb57c2f30c3a9c288b7a96f920eaeaeb324e6288785f7
|
|
| MD5 |
67528d99bb042cd608f5a9cc9bab4826
|
|
| BLAKE2b-256 |
4b6314844a05b38aae2889c22cf2483f0719b5a8ab11b64465d5af849563d394
|