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.4.tar.gz (3.9 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.4-cp38-abi3-win_amd64.whl (5.8 MB view details)

Uploaded CPython 3.8+Windows x86-64

turbo_html2pdf-0.2.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (6.1 MB view details)

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

turbo_html2pdf-0.2.4-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (6.1 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

turbo_html2pdf-0.2.4-cp38-abi3-macosx_11_0_arm64.whl (5.9 MB view details)

Uploaded CPython 3.8+macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for turbo_html2pdf-0.2.4.tar.gz
Algorithm Hash digest
SHA256 8cf52bb98e114489accdebb17537ca20369f4de0badf2d44cda441120bb7f1b0
MD5 3037e43605dedb6507866b16b02de9e7
BLAKE2b-256 068e1550c4ab0aa939d903879d254b3c24241400a6f8139f5b5e99c8416ad180

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.4-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 f179cce1baacb90238f93d4ae2877d70c971b682613801649c437835ddf44440
MD5 2e7d2b4444e5889ad6c969802d1f7ca9
BLAKE2b-256 f6d570661c46733f519af82684b8cba04041666135aaf031c124c96781512c86

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4aaa7f3e1e9d8ba85361ddb3e64191e56a38ded5de60c2040fa6dbc5184e3c18
MD5 ed4d7c63fb2a78f1e817f6e3a595c55d
BLAKE2b-256 751658de7782dfdcb084c86ae38dd9e3de2200875b0f6ee16156b314e26bab0a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.4-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 73c8857a0edb1fe7752246779d4be92dd4a0ec6f6bc7df8e8325aeda0096143e
MD5 4dea71c3ac1a9341cc75ca0fbea3a4bf
BLAKE2b-256 86ba0b760ad7362997a6df8faea1a9dba77ce178d531ec352a571dc2007c268b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.4-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 926673e23d44b314e76ec1e55acaf62b29800d73dc5f869f7a838bcd016db21f
MD5 1d33a74502676dafa722297f63f3cd83
BLAKE2b-256 8d25b4ac7cc48d5c9a0b87dfdc6c8f87817bd1de1f13e06e32a341cb68e903b5

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