Skip to main content

turbo-html2pdf (Python)

Native HTML/CSS-to-PDF engine with a Jinja-compatible templating DSL. PyO3 binding over the turbo-pdf Rust core; mirrors the Node turbo-html2pdf package 1:1.

import turbo_html2pdf as t

# Compile once, render many times.
prog = t.compile("<p>Hello {{ data.name }}</p>")
pdf = prog.render(data={"name": "world"})       # -> bytes, starts with b"%PDF"

# Warm fonts once, reuse the handle across renders.
fonts = t.Fonts.load([open(p, "rb").read() for p in font_paths])
pdf = prog.render(
    data={"name": "world"},
    css="body { font-family: font0 }",
    fonts=fonts,
)

# One-shot: compile + render in a single call.
pdf = t.render("<p>{{ data.x }}</p>", data={"x": 1})

# Inspect non-fatal lints + page count.
pdf, diagnostics, page_count = prog.render_full(data={"name": "world"})

Fatal compile/render faults raise TurboPdfError carrying .code (a stable string such as "TemplateSyntax") and .span ({"line", "col", "byte_offset"}). Non-fatal lints are returned by render_full, never raised.

API

Surface Signature
compile(template_html, opts=None) -> Program
Program.render(data=None, css="", fonts=None, images=None, meta=None, now=None) -> bytes
Program.render_full(...) -> (bytes, list[dict], int)
Program.has_header() / Program.has_footer() -> bool
render(template_html, ...) one-shot -> bytes
Fonts.load([bytes, ...]) warm registry -> Fonts

Building from source

pip install maturin
maturin develop --manifest-path crates/turbo-pdf-py/Cargo.toml
python -m pytest crates/turbo-pdf-py/tests

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

turbo_html2pdf-0.2.11.tar.gz (4.0 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

turbo_html2pdf-0.2.11-cp38-abi3-win_amd64.whl (5.9 MB view details)

Uploaded CPython 3.8+Windows x86-64

turbo_html2pdf-0.2.11-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.2 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

turbo_html2pdf-0.2.11-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.2 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

turbo_html2pdf-0.2.11-cp38-abi3-macosx_11_0_arm64.whl (6.0 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

Details for the file turbo_html2pdf-0.2.11.tar.gz.

File metadata

  • Download URL: turbo_html2pdf-0.2.11.tar.gz
  • Upload date:
  • Size: 4.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.14.1

File hashes

Hashes for turbo_html2pdf-0.2.11.tar.gz
Algorithm Hash digest
SHA256 fedfad1244283743a2b2b1521ad6076d37a33d3b9b8c00209f91d39483c7dfbe
MD5 46ff1542c6a24c6898722e978a9d9b79
BLAKE2b-256 5f6c7dedada7bfccf337690baf3f9ddd35c78c4b5e9f1bdffdbfdf34433ee7f0

See more details on using hashes here.

File details

Details for the file turbo_html2pdf-0.2.11-cp38-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.11-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f554cb529cfdbc9f05171924744070801be95f0287c8e1cc115afc3a6b58ac29
MD5 a49fca6ded76f92302f90c14f881d982
BLAKE2b-256 04915b47e8e80adab46e81f2cc518505266da5a8f03ed72e45c0bb0b9d450efd

See more details on using hashes here.

File details

Details for the file turbo_html2pdf-0.2.11-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.11-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1e2ee482e03cc5144538ccc6a2870c655a689f0b64a68f0a47a56bf5166c4c5c
MD5 82514e44193794d75556239eb79b8a2a
BLAKE2b-256 65a651eb5b037c5a02d8d366e8ec6844533ba9b1c7c6906a02e91697880580a6

See more details on using hashes here.

File details

Details for the file turbo_html2pdf-0.2.11-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.11-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6cbb03a49b9ba7ab4ef4402bd41a66f5c8370f6120cc1a84db1684d5987194f7
MD5 6746fc80aab7ebc0922f2fedf70225a5
BLAKE2b-256 6c846ad25a0a07270af2771718f72a950f7c19b447152166a688ca0df604ed3b

See more details on using hashes here.

File details

Details for the file turbo_html2pdf-0.2.11-cp38-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.11-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2272fcf85c40b2cf49203b74f29b74622d1ef9d49381b77ddfcb62861ae0a1b0
MD5 82fdec31766fb920a59029d3629138a6
BLAKE2b-256 0297c68ac423197918de58d91011b49fd5761391eb04b57f4d5b21c11457ed7b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page