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

Uploaded CPython 3.8+Windows x86-64

turbo_html2pdf-0.2.6-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.6-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.6-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.6.tar.gz.

File metadata

  • Download URL: turbo_html2pdf-0.2.6.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.6.tar.gz
Algorithm Hash digest
SHA256 ff5a909cfa7517087013cb5caf1b88c6154f41d104b76e9f80c2a25af0e0f025
MD5 2530d8fe442291847074e362f24db74e
BLAKE2b-256 3be18a7b511ac2a646c93d2f353beb886702d79c100012eeac969ddc341f7b33

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.6-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 cd4bd67e644891fe1c853e52bc0ae26970cae80496c31a34fc9fb56099443b52
MD5 1e595b016551fd2be49c0548a8dc31ed
BLAKE2b-256 c5df906b81fd849befa972f0a3f7ca22f6cfa38a243584a06c64caa57861599b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.6-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 29175109d57eab02d9036359f04193f8b0adda21e96d50cde68a6ce2cb29863e
MD5 f1a0c604e2911882aa5e02211205fc55
BLAKE2b-256 5939326f58f0ddeb17546744db610a287241a2837fa00a214745854390dc406e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.6-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c194d3d6b7c60487c6ca3dde0d174fba3af317b27dab37f53078f28422e0b12e
MD5 c46685f9081a257cf4e779d881b3bcae
BLAKE2b-256 46112fb3f982bd5ad0ffb0a20b68e7d7b602b3d197fd6b2df510311996c2c12f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.6-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9130c4b35d332846a072356e611d111aac46b66e4f1b407e3e2d1ed2e3440ef5
MD5 012f8052de64026da35c5b3a88fa1080
BLAKE2b-256 3cb3712a659bc744baacd900bd9dd57aa5aca8f91ba7c40086bf17c1cf109534

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