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

Uploaded CPython 3.8+Windows x86-64

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

File metadata

  • Download URL: turbo_html2pdf-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 a2b490e9a06f6e7f8fa7a67f7000c1829c86341af7c22e57c358ac4a6dc2824d
MD5 b9c04488aab2f0a5a6dd8f190ef73b4e
BLAKE2b-256 e5ab3ad7e3f73d90a37edc3a15a5d23bf37c549dfc06b4f56f25048970eb5096

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.1-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 b1243a3fef8b2f78ec20331c97d1016d33721daf636508c521bc6fa1918324ac
MD5 05f33673315f2748b7167a5015b23cd4
BLAKE2b-256 106550ce590bc70226fb95d1233bda818c429c41e5258577eef2d45e5742bd1b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.1-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ac75b323d1895649fe9f03f35454854db3eeafebe8ba6a0c51f033ee3a86639
MD5 8bbf77152219adf479a3e10348cdb7e1
BLAKE2b-256 f77351cf0e3dba45adc6d7f5ad0957189b9a94ffc0fbeb7effb84abfbbaa294a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.1-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6b15f80f4b553a98d6ea9d9120b9a442962b81c0f60990daa332d91f837b3f74
MD5 816ebce28026e1111c28a626b11ad068
BLAKE2b-256 ecbdff366ab75a22243add402bd763e03e8aefd8a8d555c4ab90995fd51fd369

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.1-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 b3c9c9b4ec5382d884cdb28c9027a0a41731450a13b78de6d1ba3ac07e7d4980
MD5 9d5733326989062065ed00fa7f81f8e9
BLAKE2b-256 8e133c30785c831004e2af73c3aa6e2438458162d4e9f98cf8f358fcfe0bdb21

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