Skip to main content

Native HTML/CSS-to-PDF engine with a Jinja-compatible templating DSL (PyO3 binding over the turbo-pdf Rust core).

Project description

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

Project details


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

Uploaded CPython 3.8+Windows x86-64

turbo_html2pdf-0.2.1-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.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: turbo_html2pdf-0.2.1.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.1.tar.gz
Algorithm Hash digest
SHA256 5274b664db7de4b8d8463f186c735147469e29d9b40cd7d55cafba7a2e8c3056
MD5 b0f5c38fab4ac780e3adf9bdb7e84a37
BLAKE2b-256 06900a8d3469c99432a4b51c33e33602c7452d5ecf2f27713296cc9940f34e57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 7500800b84280f705917efb31ee997048d928c307be344d2018db1e4fb1dd154
MD5 adb6902153ff410e257425a3e0e12db6
BLAKE2b-256 2f6dd009b3a8f7dfbbe628fd5f70725e218a53e39cd0f9f8c917f37926f138ea

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 99d39f134c06973d459a768c613f76c1a52365243827d353eb079aae8eb9343e
MD5 d1174819a58fd946671609c7e7f63e99
BLAKE2b-256 471a64449ec6b4e164e84ee31a276d0df5c054282ad7ab0f48bfc1a7d8f996f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 87f54bcbcfc0eb4f472dc550a7083d517c11b5cdcc7b98845ec5833e3e1cc528
MD5 ae497e8f765a0ecbfb3ed09679d21ea3
BLAKE2b-256 35992c4dd8993a789d536df4a4e9cccfb4e7f5b00603257e0ad173c6dd3f6ff9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f4528d08a15c5be2ad0c9904748546f0a736334ea569204fc5fa4684faa5291d
MD5 26bb94da754281b1783ebc64dee5c8c2
BLAKE2b-256 861e32042eef3a7d8b39eb0ce0cc2e01653dafdda9808ee10581ad324e2877cc

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 Pingdom Monitoring Sentry Error logging StatusPage Status page