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.3.1.tar.gz (4.1 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.3.1-cp38-abi3-win_amd64.whl (5.9 MB view details)

Uploaded CPython 3.8+Windows x86-64

turbo_html2pdf-0.3.1-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.3.1-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.3.1-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.3.1.tar.gz.

File metadata

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

File hashes

Hashes for turbo_html2pdf-0.3.1.tar.gz
Algorithm Hash digest
SHA256 dfb990fe7c0368d8b387e88910ea3faaef847d5ab2bbe2360d9579bc0a8dac40
MD5 add9ff828d29e44f8146dd7082114079
BLAKE2b-256 3cef5c36d64c95757abe0bb8d56364c6d3302567729b3dc5f009035e6b51b8d5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.3.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 4c8aa52b5ea63b9856929512c14a29c3c29860b57963cb6cb1e64536be80e96f
MD5 6bb84ad4215eb8797137f34a1b61184c
BLAKE2b-256 32e7e686966003c1b48450a36dc1669bd34ad1c5c8b5b5e6c7e34bb67ad5749c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.3.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 da42e8ba1ac867fdef81d15f188054401ed2c2040340d93dbf20c7882a05f99a
MD5 4c40c8acfe0dbd9141e981d5adf25b67
BLAKE2b-256 71eba7d2289e24835f28fd28a39566e2ab3b4727d6370eb7282382f218cbde15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.3.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7f1373d144f6ea02b112efa1068e63672dbd877cc095f1a8dff77e3050c70935
MD5 868aceaf57d1431ea92041faf1767c8b
BLAKE2b-256 b55459cda4288091a9178b1be7f89ef538cb315ce36cd41c9a6e1f0fa3c9d22a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.3.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 3280e5d9dfea9cc190ea654ff1c970492d715f2bc54031986bfec470904e6f32
MD5 04a472263be1488a913e426c79c61082
BLAKE2b-256 3895911d00b3eb87b6a5bb683520ebe941831d84c89e045c3c32905bdceafb60

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