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

Uploaded CPython 3.8+Windows x86-64

turbo_html2pdf-0.2.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.2.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.2.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.2.2.tar.gz.

File metadata

  • Download URL: turbo_html2pdf-0.2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 7c8409a7f2f39e5fd4defd8a539e09afdaca6a4276f11aa61135132eaec6d075
MD5 273689bf0ce8baa0010ccd70d5ef7fa9
BLAKE2b-256 b9cc6ac13a585ad12f779f4dba1b69f8fbdebecd548f04b492531c2f14d22ad4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.2-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 a2ecef0ec903850ebdd2efc870fbe8df2e2b81b441521d7031f3b2976fb0287e
MD5 f572c545292a23155cba59c59d377a74
BLAKE2b-256 19d33221ff50dad0d1e799b3d76c8bee8ae6acc19c56e4d41ae5b68a1e98fc81

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.2-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 898efcc7cd22b335f5264e544d5458a2fd3b220ee94fdc80b2f36ed3922041bc
MD5 ce5cb9c8b3fd5225ce202a9fa5451e9c
BLAKE2b-256 14a0695089e24ec4a8c5285a9c670c63f0f28830b4691cc7a77d7c003873b13d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 291495706c22d0c3653c3f2541e6d758f738df3bc5c339ee07c65f9bd6c3e5d7
MD5 cb489ecf64c5b5fac8afea4604e2197d
BLAKE2b-256 4f84eda827ae2b350ab4b0b5cd728ce0d78d287609fd8e2717d0213c1a6eb803

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.2-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 341c7f6babf7df9a7244f3f78ab68d25570bedf7490e1c49a1da92f966fe2018
MD5 0d9f9df81d7b222e2134f5f06a243fd2
BLAKE2b-256 a3207a48c31f264b3e031538f56fa7369157a09590b460d0594e1700425e56c3

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