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

Uploaded CPython 3.8+Windows x86-64

turbo_html2pdf-0.2.13-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.13-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.13-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.13.tar.gz.

File metadata

  • Download URL: turbo_html2pdf-0.2.13.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.13.tar.gz
Algorithm Hash digest
SHA256 bfbece9b68531cf50cb77f6b05fa4614bec6935261ba471abbc0c7f74f454a33
MD5 eea1504ddaf67a372c500c5126a61d67
BLAKE2b-256 7ec3905de8c9cc08214f18c31d5b1cb680d47f2abbd0ad3b2c4434fbe55ea497

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.13-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 c8043fd43d004b0713e71bb9d0983791a67519975ff313e34f7dda8e39c30b75
MD5 c866ec2d19f101ba3c579b2c0fd732da
BLAKE2b-256 63806724d67526ad1092774019dccb8dcab493e442e14b9daf3eac9cf8be04ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.13-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ddc6fcd0faa7b4e67bd8dcefda712e06f81fdb8e5b96e48b9f15d81dce0ccc13
MD5 5c9172feaa2ef8c70d5da2423d12499f
BLAKE2b-256 a547b0b531128c6187fce50658a34b4e4d5d656a408324263165b7f978a1180e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.13-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9add4539b7dee312007d087b03f46b1fb3a407c7e86ede2a69989c109d53b457
MD5 4db929f3a3a1461e94f713ed44f76b84
BLAKE2b-256 0f7ce5d4d569ba3ddeaac6c5a941676e226ee3c0428b188f8d3ae6f25eebe427

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.13-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 20b03da8193e9ab8ec6ab97b8547a2321bab90c05027e5d233d12b26d3927ac9
MD5 468b5dc6db4ff55eea5e26c09064fee1
BLAKE2b-256 796ac88542888494e7157c7d66d9a5f3d5f71e95ba1dc3b59269d2d081102342

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