Deckle - PDF generation API for developers. HTML in, pixel-perfect PDF out.
Project description
Deckle Python SDK
PDF generation API for developers. HTML in, pixel-perfect PDF out.
Installation
pip install deckle
Quick Start
from deckle import Deckle
df = Deckle("dk_live_...")
# Generate a PDF from HTML
pdf = df.generate(
html="<h1>Invoice #1234</h1><p>Amount: $500</p>",
options={"format": "A4", "margin": "1in"}
)
print(pdf.url) # https://cdn.getdeckle.dev/gen_abc123.pdf
print(pdf.pages) # 2
Generate from Template
pdf = df.from_template(
template="tmpl_invoice_v2",
data={
"company": "Acme Corp",
"items": [
{"description": "Consulting", "qty": 10, "rate": 150}
],
"total": 1500
}
)
PDF Options
from deckle import PDFOptions
pdf = df.generate(
html=invoice_html,
options=PDFOptions(
format="A4",
margin="1in",
orientation="portrait",
header="<div>Acme Corp</div>",
footer="<div>Page {{pageNumber}} of {{totalPages}}</div>",
print_background=True
)
)
Templates
# Create
template = df.templates.create(
name="Invoice",
html_content="<h1>Invoice for {{company}}</h1>",
schema={"company": "string", "total": "number"}
)
# List
templates = df.templates.list()
# Update
df.templates.update("tmpl_abc123", html_content="<h1>Updated</h1>")
# Delete
df.templates.delete("tmpl_abc123")
Error Handling
from deckle import Deckle, DeckleError, RateLimitError
try:
pdf = df.generate(html="<h1>Hello</h1>")
except RateLimitError as e:
print(f"Rate limited. Retry after {e.retry_after}s")
except DeckleError as e:
print(f"Error {e.code}: {e.message}")
Development
pip install -e ".[test]"
pytest # run the test suite (httpx requests are stubbed via respx)
make test # same, via the project's Makefile
License
MIT
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
deckle-1.0.0.tar.gz
(10.6 kB
view details)
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 deckle-1.0.0.tar.gz.
File metadata
- Download URL: deckle-1.0.0.tar.gz
- Upload date:
- Size: 10.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7526f325d0bdcb9397c647f0c9b8011891a8e9c8d4e0219313bb6a959c14602c
|
|
| MD5 |
088f144cd678859301fe9d1f13584dc4
|
|
| BLAKE2b-256 |
567ab3a3f02e64d26ab3cc673752145cb3829da079dfd103765b7a19a9d798b8
|
File details
Details for the file deckle-1.0.0-py3-none-any.whl.
File metadata
- Download URL: deckle-1.0.0-py3-none-any.whl
- Upload date:
- Size: 9.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8c139b0b23cf35db2cece1e96a4ba4b6075d3d50539a94c8d163cd6ac1fe622
|
|
| MD5 |
8ebcfc0427839849178a5292da9d7320
|
|
| BLAKE2b-256 |
93fa38921fe37bdb8cd91eeca835869653b1b46aa751f345434642d29ef5f3ba
|