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

Uploaded CPython 3.8+Windows x86-64

turbo_html2pdf-0.2.0-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.0-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.0-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.0.tar.gz.

File metadata

  • Download URL: turbo_html2pdf-0.2.0.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.0.tar.gz
Algorithm Hash digest
SHA256 707dbe633e81d19243c8b7beb488d1ff40a4d8475dced615be4980e717e1bf01
MD5 c423723eb0aa6bb9ef76cadba3507bed
BLAKE2b-256 616f06a4a233733fd072be8594ba121ba1130857ad1904aadf68fbd2af93fac1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.0-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 bbd3ba9f671d40766d987459c8fa3794fb086e465a1d0755b232835052bb2eee
MD5 5a6759ca7168a3af78c874434dcb8fca
BLAKE2b-256 4ecf4e1e359cbf5032c8b02ee4a7794e86cb1639c5802619e963333996907bdd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 603e6740bf0c224890933fb182510f8cacc7fa7e479ce45a43419a2b0d1f3d59
MD5 5cc081289fac623f2c7f9561005b1711
BLAKE2b-256 6d17c754809c14c0d0fafad1af5d04ca742f9ea996d7d706c25605bc41e788dc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.0-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 34b18f63a5e4a1f206de4fd65c012544b6bca000d879eba3c43efa395212b6c1
MD5 0c8371c2f4f0ae83ac24a99f85d303be
BLAKE2b-256 548550096b3c53e47a51153fe077e4f9ceb77e1c0ab5545e7637e404057ae892

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.0-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 06d03a8322abde156a7ac999e43ca8e10f97080223438b73113c150a3a5b973f
MD5 d859bf976260baaa87a7e5ee7addd240
BLAKE2b-256 a4dcea8be65fb378cf2e2adb8c62b8686e87ab6e21e216c8f7a999fa6f01b287

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