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

Uploaded CPython 3.8+Windows x86-64

turbo_html2pdf-0.1.2-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.1.2-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.1.2-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.1.2.tar.gz.

File metadata

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

File hashes

Hashes for turbo_html2pdf-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0955814d56f60025face06d63818bd1ea55a3ca81acd54f0d2851b1a41c6c0eb
MD5 82344c31299719b926577a3c9a2aa42b
BLAKE2b-256 119dffd8d3327bd3e9c86d7904c2a06dd113f78d431919658a7810b9c3dd8cc9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ae0f8a2317db6d9f1da93d8a24fb77ebd54a37446500913b775c53ba261266ba
MD5 972fa4dc6352eb2774d18382dae4c69e
BLAKE2b-256 4e87b535a8508bb275403590f9a0ccd6e44c5ba02b1e25c746b54621b31d2c72

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 db782f2a5fddd0d64b6c79fe05ae2f7b5b7b8520c983d4683d4bb8b85c7959f7
MD5 bf9ad2f395c48f9b51fcb181e5359f50
BLAKE2b-256 6e1d0cd54d1e8305e5c4bef71320681ce29c691ae2650cff379eeaadfbcd3dab

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 425d67e1c1fe5771eb49f6f1eac317251403b764971a2dfbf5a4e27e0846cf73
MD5 2806ad403ccd9d94f51e230a6d09e639
BLAKE2b-256 93cbc219ec12be69e298cfa5c6b982cbad0b8ea3b1e7a9eb55f9304ce792a48d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 1b2be487e6c3eb37bef69344e07e9e52170e162b87d620e88c3e432bb75abe3d
MD5 33da3e206bcd3d80aa74a4dfba1b65c1
BLAKE2b-256 95463f043bd4479a18dab07d8f4aa44234bad911cbcf333e6645c82b6b76e6ef

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