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.14.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.14-cp38-abi3-win_amd64.whl (5.9 MB view details)

Uploaded CPython 3.8+Windows x86-64

turbo_html2pdf-0.2.14-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.14-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.14-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.14.tar.gz.

File metadata

  • Download URL: turbo_html2pdf-0.2.14.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.14.tar.gz
Algorithm Hash digest
SHA256 168d0a2d4762b9bceaaef0255fed1906ed55609f66ac23fb433491d53d1c540f
MD5 0702ff5d438822ed10eba2ccce1cae35
BLAKE2b-256 904b69cfe9d74d26e3af5d8c44347713c75d16e72e6a27d1042e3e109f35e5f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.14-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 21e11ec88fdf296b60205e2bf95c18158c1615545aabe963cdfdbe2b1941b85e
MD5 de74514d4a9242e06ab3fae1d6d01810
BLAKE2b-256 2cb35eff93a4ae4dd48cc237d176150d7724bc308aabd2aab97a98e1079efdd2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.14-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fb2ef61bdfdf5cad739f91eb4cfbc41edf43269485f72c999b4add9839d22824
MD5 0d77cdaaa57fa99eca2991237f8bc4d8
BLAKE2b-256 940a95dec1d28166f26f29948dfc92575f9e7c83896c5189977ca1cd75b0d29f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.14-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 56e2f162899267e693a3282526bba9679896cd62bd678c1cf9262a10dbe2c7a7
MD5 b5bf30aec3cdf01702462046bec9c6fb
BLAKE2b-256 c7c9e7598d301195ef8a1fc97024a92447db4df92f0e81ee0cfe8839ca7e4938

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.14-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 97ee8e60f9104cf55f342fca69438fa9bd04b1e657a00d1ede0595ffde6e599e
MD5 b4173bd990a277981f799f2a20b4172f
BLAKE2b-256 355b063d8d73374a68054f74bc71b48bc5a137d8a96ad231001bf28b08a337e6

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