This release is a pre-release and may not be stable for production use.
Pressjet for Python
Beta 3 · Install this SDK from the versioned GitHub release.
The official Python SDK for Pressjet, an open PDF rendering service. Build a document tree with plain functions and render it to PDF, preview it as images, draw flows, merge, rasterize and sign PDFs.
- Python 3.11+, fully typed (
py.typed), no dependencies beyond the standard library. - A synchronous
Clientand anasyncioAsyncClientwith the same methods. - Retries, timeouts and typed errors as described in the SDK design.
Install
python -m pip install https://github.com/tonysantana1492/pressjet/releases/download/v0.1.0-beta.3/pressjet-0.1.0b3-py3-none-any.whl
Quick start
import pressjet
from pressjet import document, page, text
invoice = document(
page(
text("Invoice INV-001", style={"fontSize": 20, "fontWeight": "bold"}),
text("Billed to ", text("Acme Corp.", style={"fontWeight": "bold"})),
size="A4",
style={"padding": 40, "fontFamily": "Helvetica"},
),
title="Invoice INV-001",
)
with pressjet.Client(api_key="pj_sk_...", base_url="http://localhost:8080") as client:
pdf = client.generate(invoice)
with open("invoice.pdf", "wb") as file:
file.write(pdf)
examples/invoice.py is a complete example.
The signature example builds a section you can append to a contract.
Choose line (default), box or square (PDF sample).
To mix appearances, pass individual
signature_field(name, appearance) values to signature_section. With the matching CLI on
your path, this command generates a two-signer sheet with the optional diagonal draft stamp.
python examples/signatures.py --style box --watermark diagonal "Ana López" "Jordan Lee" | pressjet render - -o signatures.pdf
Builders
from pressjet import document, page, view, text, image, barcode, table, page_number
| Builder | Children | Keyword properties |
|---|---|---|
document(*pages, title=None, author=None, lang=None, created=None, conformance=None, verification=None) |
pages | lang: a language tag such as "es-MX"; created: ISO 8601; conformance: "pdf-a-2b", "pdf-ua-1" or a sequence of them; verification: a VerificationSettings dict |
page(*children, size=None, style=None) |
views, text, images, barcodes | size: "LETTER", "A4", "LEGAL", "A5", optionally with landscape or portrait ("A4 landscape"), or a width and height ("210mm 297mm") |
view(*children, style=None, fixed=None, hide_on_first_page=None, wrap=None, break_=None, keep_together=None, keep_with_next=None, role=None, level=None, alt=None, id=None) |
views, text, images, barcodes | |
text(*children, style=None, fixed=None, hide_on_first_page=None, wrap=None, break_=None, keep_together=None, keep_with_next=None, role=None, level=None, alt=None, id=None) |
strings, numbers, text, images | |
image(src, style=None, fixed=None, hide_on_first_page=None, wrap=None, break_=None, keep_with_next=None, role=None, alt=None, id=None) |
none | src: bytes, base64 or a data: URL |
barcode(format, value, error_correction=None, columns=None, style=None, fixed=None, hide_on_first_page=None, wrap=None, break_=None, keep_with_next=None, role=None, alt=None, id=None) |
none | format: "qr", "pdf417", "datamatrix" or "code128" |
table(columns, rows=None, style=None, header_style=None, row_style=None, repeat_header=None, keep_with_next=None, break_=None, id=None) |
none | columns: header strings or {"header", "width", "align", "style"}; each row holds one cell per column: a string, a number, None or a node |
page_number(template="{pageNumber} / {totalPages}", style=None, fixed=True, hide_on_first_page=None) |
none |
-
Positional arguments are children; properties are keyword-only.
-
fixed=Truerepeats a node on every page (headers, footers),wrap=Falsekeeps it on one page andbreak_=Truestarts it on a new page. The trailing underscore avoids thebreakkeyword; the node holds the schema's"break"key. -
keep_together=Truekeeps a view or paragraph on one page when it fits, andkeep_with_next=Trueallows no page break between a node and the next one (a heading and its first paragraph). -
role(aRolesuch as"heading","table"or"artifact"),level(a heading's level, 1 to 6) andalt(alternative text) tag the node for PDF/UA-1.id(unique, up to 64 ofA-Z a-z 0-9 _ . : -) lists the node in the layout report'sanchorsand makes it a named destination in the PDF. -
document(lang=..., created=..., conformance=...)write a PDF/A-2b or PDF/UA-1 file: PDF/A-2b needscreated, since the engine reads no clock, and PDF/UA-1 needstitleandlang. -
barcodedraws a symbol as vectors, never split across pages; it goes where a view or an image block goes, not inside text.valueholds 1 to 4000 characters, with{pageNumber}and{totalPages}replaced on each page.error_correctionis"L","M","Q"or"H"for QR and 0 to 8 for PDF417, andcolumns(1 to 30) sets PDF417's data columns. Without a width or height a code takes one point per module;style={"color": ...}sets the dark modules. -
document(verification=...)stamps every page's margin with a code that names the document, a digest of its source, the page number and total and, when the server holds a verification key, an Ed25519 signature.idis required (up to 64 ofA-Z a-z 0-9 _ . : / -);url(anhttps://address a phone camera opens),format("qr","pdf417"or"datamatrix"),position("bottom-right"by default, or"left-edge"and so on),size(18 to 144 points),insetandcaptionare optional. The code is sized to fit the margin, so it never covers content:lease = document(page(...), verification={"id": "OH-2026-0417", "url": "https://example.com/v"})
-
NoneandFalsechildren are dropped and nested lists or tuples are flattened, so conditional content and comprehensions read naturally:view( [text(line.name) for line in lines], is_paid and text("PAID", style={"color": "#16a34a"}), )
-
Numbers inside text become strings (
2.0becomes"2"). -
Properties left unset are omitted, never sent as
null. -
Image bytes are encoded as standard padded base64; a string
srcis passed through unchanged. -
Nodes are plain
dicts (typed asTypedDicts such asDocumentNode) thatjson.dumpsserializes tospec/document.schema.json. -
Styleis aTypedDictwith every style property of the schema, using its camelCase keys andLiteraltypes for the allowed values, so editors and type checkers complete and check them. It includesdisplay("flex"or"block"),boxSizing,marginVertical,marginHorizontal,fontStyle,textDecoration,orphans,widows,transform,transformOrigin, the per-side borders (borderTop, orborderLeftWidth,borderLeftColor,borderLeftStyleand so on) andborderStylewith"none"and"hidden". -
fontFamilyandsizeare open strings:FontFamilysuggests the built-in families (BuiltInFontFamily) but takes a CSS-style list such as"Brand, Archivo, sans-serif", andPageSizesuggests the named sizes (PageSizeName).
Client
| Method | Returns |
|---|---|
generate(document, *, fonts=None) |
PDF bytes |
html(html, settings=None) |
PDF bytes |
preview(document, options=None, *, fonts=None) |
Preview(pdf, total_pages, pages) |
check(document, *, fonts=None) |
Check(ok, page_count, pages, diagnostics, dropped, anchors), the layout report |
check_html(html, settings=None) |
Check, the layout report of HTML as html prints it |
verify(code, *, public_key=None, layout=None) |
Verification, what a scanned verification code says |
draw(flow, append_pdfs=None) |
PDF bytes |
merge(pdfs) |
PDF bytes |
rasterize(data, options=None) |
Raster(total_pages, pages) |
sign(pdf, *, name, reason, signing_time) |
PDF bytes |
info() |
the server's capabilities as a dict, with verificationKey (base64url, or None) |
health() |
{"status": "ok", "version": ...} |
check reports what is wrong with a document without rendering it, each problem with a JSON
Pointer and a fix (the codes).
A document that cannot be rendered is a report with ok false, not an exception, so it may be any
JSON value, such as one a model wrote:
report = client.check(json.loads(model_output))
for problem in report.errors:
print(problem.code, problem.pointer, problem.fix)
if any(problem.code == DiagnosticCode.MISSING_GLYPH for problem in report.diagnostics):
...
-
barcode_too_small(withmodule, the module width in millimetres) andbarcode_coveredare warnings about barcodes and verification codes. -
anchorsis a list ofAnchor(id, page, x, y, width, height), one per node with anid: the page it first appears on (from 1) and its box there, in points from the page's top left. It is empty when no node has anid. -
fontsis a sequence ofFontFacedicts, at most 32:src(TrueType or OpenType bytes, which the SDK encodes as base64, or a base64 string) and optionalfamily,weight(1 to 1000) andstyle("normal","italic"or"oblique"). The document may then name the family infontFamily:brand = {"family": "Brand", "src": Path("Brand-Regular.ttf").read_bytes()} pdf = client.generate(invoice, fonts=[brand])
-
verifytakes the text a scanner read from a verification code, in either form, and returnsVerification(valid, reason, id, digest, page, total_pages, signature, document_matches).signatureis"valid"or"invalid"when a key is known (public_key, else the server's own),"unchecked"when none is, and"absent"for an unsigned code. Passlayout, the source document you kept, to learn whether the code was printed from it. A code whose signature is"absent"or"unchecked"proves only whatdocument_matchessays. A publishable key may call it:result = client.verify(scanned_text, layout=lease) if not result.valid: print(result.reason or "the code does not match")
-
pagesis a list ofPageImage(page_number, width, height, png), wherepngholds the decoded PNG bytes. -
optionsis aRasterOptionsdict:scale,maximumPages,maximumInputPixels,mimeType,maximumImageDimension. To rasterize an image instead of a PDF, setmimeType. -
Binary inputs (
pdfs,append_pdfs,data,pdf) acceptbytes,bytearrayormemoryview, which the SDK encodes as base64, or a string that is already base64 or adata:URL. -
flowis a flow as plain JSON data (spec/flow.schema.json). -
signing_timemust be a timezone-awaredatetime; it is sent as RFC 3339 in UTC. A naivedatetimeraisesValueErrorrather than guessing its time zone. Usedatetime.now(timezone.utc). -
Every method also takes keyword-only
timeout(seconds) andheadersthat apply to that call.
Async
AsyncClient has the same options and methods, as coroutines:
import asyncio
import pressjet
async def main() -> None:
async with pressjet.AsyncClient() as client:
pdf = await client.generate(invoice)
asyncio.run(main())
It runs the standard-library HTTP transport in a worker thread with asyncio.to_thread, so calls
never block the event loop and the package keeps zero dependencies. Cancelling a call stops
waiting at once; the worker thread finishes the HTTP exchange in the background, bounded by the
timeout.
Errors
All errors derive from pressjet.PressjetError.
| Error | When |
|---|---|
APIError |
The server refused the request. Has status, code, title, detail, request_id and retry_after (seconds or None). |
PressjetConnectionError |
The server could not be reached or the connection failed. __cause__ keeps the underlying error. |
PressjetTimeoutError |
The call, including retries, did not finish within the timeout. A subclass of PressjetConnectionError. |
ResponseTooLargeError |
The answer was larger than max_response_bytes. |
APIError's message reads "<title>: <detail> (<code>, request <request_id>)". ErrorCode is a
str enum of every code in spec/openapi.yaml; an answer that is not a
problem document gets the code http_<status>.
from pressjet import APIError, ErrorCode
try:
client.generate(invoice)
except APIError as error:
if error.code == ErrorCode.INVALID_DOCUMENT:
print("Fix the document:", error.detail) # names a JSON Pointer such as /children/0
else:
raise
Configuration
pressjet.Client(
api_key=None, # else PRESSJET_API_KEY; sent as Authorization: Bearer <key>
base_url=None, # else PRESSJET_URL, else http://localhost:8080
timeout=60.0, # seconds for the whole call, including retries
max_retries=2, # after 429, 502, 503, 504 and connection failures
max_response_bytes=128 * 2**20, # larger answers raise ResponseTooLargeError
headers=None, # extra headers on every request
)
Options are keyword-only. Rendering is a pure function of the request, so every operation is
safe to retry. Retries wait for Retry-After when the server sends it, otherwise
0.5 s × 2^attempt with ±25% jitter, capped at 8 s, and never past the timeout: when the wait
would end after the deadline, the last error is raised at once. The timeout bounds each socket
operation and is checked between reads of the answer. Every request sends
User-Agent: pressjet-python/<version> and a fresh X-Request-Id, one per attempt (pass your own
in headers to trace a call). Requests go through urllib.request, so the standard proxy
environment variables apply.
Client holds no open connections; close() and the context manager exist so code can manage it
like other clients.
Development
docker run --rm -v "$PWD/../..:/repo" -w /repo/sdks/python python:3.13-slim \
sh -c "pip install -q -e '.[dev]' && pytest -q && mypy --strict src tests examples && ruff check ."
Integration tests run against a real server when PRESSJET_TEST_URL and PRESSJET_TEST_API_KEY
are set (scripts/test-server.sh starts one), and are skipped otherwise.
License
Apache-2.0.
HTML invoices
Use client.html_multipart(html, images, settings=None) to attach raw JPEG or PNG
bytes keyed by the image's src. See binary HTML images.
client.html("<p>Invoice 42</p>") returns PDF bytes. settings is an HtmlOptions dict:
stylesheets, images (names mapped to bytes or base64), omitImages, profile
("standard", "pdf-ua-1" or "pdf-a-2b"), conformance, created, lang (when the HTML has
no lang attribute), fontFamily, fonts (FontFace dicts, as above), engine
("native", the default, or "reference" for the server's optional WeasyPrint service) and
verification (a VerificationSettings dict, as for document; the native engine only).
client.check_html(html, settings) sends the same HTML to /v1/check and returns the layout
report, the compiler's findings (ignored_css, ignored_html, missing_resource,
font_substituted, invalid_request) first. Its settings are an HtmlCheckOptions dict, the
same keys without engine and verification. Deployment and limits
Metadata
Release files for pressjet 0.1.0b3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pressjet-0.1.0b3.tar.gz | 80.3 kB | With provenance | Details for pressjet-0.1.0b3.tar.gz |
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pressjet-0.1.0b3-py3-none-manylinux_2_17_x86_64.musllinux_1_2_x86_64.whl | Python 3 | none | Linux musl 1.2+ x86-64, Linux glibc 2.17+ x86-64 | Details for pressjet-0.1.0b3-py3-none-manylinux_2_17_x86_64.musllinux_1_2_x86_64.whl |
| pressjet-0.1.0b3-py3-none-manylinux_2_17_aarch64.musllinux_1_2_aarch64.whl | Python 3 | none | Linux glibc 2.17+ ARM64, Linux musl 1.2+ ARM64 | Details for pressjet-0.1.0b3-py3-none-manylinux_2_17_aarch64.musllinux_1_2_aarch64.whl |
| pressjet-0.1.0b3-py3-none-any.whl | Python 3 | none | any | Details for pressjet-0.1.0b3-py3-none-any.whl |
Total release size: 19.3 MB
Release files / pressjet-0.1.0b3.tar.gz
| Download URL | pressjet-0.1.0b3.tar.gz |
|---|---|
| Size | 80.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7d816717e2b245c464c4f7e91e8af7d35e9232a12e05657d61068b60eb5b8d1
|
|
BLAKE2b-256 checksum How to use checksums |
3c5b4a6b02b44e91741d2168a6a498b3db398018a97e4b7713d957901339dedd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / pressjet-0.1.0b3-py3-none-manylinux_2_17_x86_64.musllinux_1_2_x86_64.whl
| Download URL | pressjet-0.1.0b3-py3-none-manylinux_2_17_x86_64.musllinux_1_2_x86_64.whl |
|---|---|
| Size | 10.0 MB |
| Tags | Linux glibc 2.17+ x86-64 Linux musl 1.2+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
3150a9fbb3b22b631d8bc53c4f71dfcffe8326c09e9612454fbf5faf496c7a8d
|
|
BLAKE2b-256 checksum How to use checksums |
3dd8f8e0f821aa7db8c20479ba7fce9d35342a449d5fb5649beeefe3796d05fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / pressjet-0.1.0b3-py3-none-manylinux_2_17_aarch64.musllinux_1_2_aarch64.whl
| Download URL | pressjet-0.1.0b3-py3-none-manylinux_2_17_aarch64.musllinux_1_2_aarch64.whl |
|---|---|
| Size | 9.1 MB |
| Tags | Linux glibc 2.17+ ARM64 Linux musl 1.2+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
b5f07cf719daf23e5703962d0495e02cc5aaeaccf740647448b2bad3a8574f20
|
|
BLAKE2b-256 checksum How to use checksums |
51f6973b5581701b1097513dd312c2ffbf2b313d5029086b6ed46ed55198b1a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logRelease files / pressjet-0.1.0b3-py3-none-any.whl
| Download URL | pressjet-0.1.0b3-py3-none-any.whl |
|---|---|
| Size | 38.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
af204737241313c8659571bd7e73d86e4b0a53658c401a92be6df0d3d8c06756
|
|
BLAKE2b-256 checksum How to use checksums |
b2a79eb0ac827d29c22df24f377ff6691056ef56dce913137e04d34d84aae341
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logSecurity for pressjet 0.1.0b3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 4 files in this release have been uploaded with provenance metadata.
Attestation for pressjet-0.1.0b3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.