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

Uploaded CPython 3.8+Windows x86-64

turbo_html2pdf-0.1.3-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.3-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.3-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.3.tar.gz.

File metadata

  • Download URL: turbo_html2pdf-0.1.3.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.3.tar.gz
Algorithm Hash digest
SHA256 4de01e53d4948dc3cde82d44756f02fa3386903672367ec0127641fdea0966fc
MD5 dc9a63b3fc6c2d6e7dd4d019ac2fd948
BLAKE2b-256 755d4884ecbc1a398d91754d4292b0c4f498e251b89b0b1854ba2220d07f1359

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 75eadfa54c15326789985044f5834e56db8e6c0281ae880d5f747246794efed9
MD5 240c330582a7c7531834894c489b04b4
BLAKE2b-256 6af07fe3f1323d53cded4f31727cac4c6f47648f85a45275c5bd7681318f48a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d69251bbb92ef9e43bd15e46e99d065b24d418483db4bb4d2e4e858709a250a6
MD5 d8ae4b37f1048aee3caca69e4ed5b771
BLAKE2b-256 0cb4a2e3a7509348cbfcd73d5f9bdc50fc0fa1bf3a0f36015ba84a2ac70aa072

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6566fd87acef559db3338cc834f8c20a2b524eca697a610c153792584631574c
MD5 20a6af8bcbd7a4696ac92d975fce8a02
BLAKE2b-256 62bbed28c5778c8a3795edcb1233da9f068f98f52019cdfe3041ce8e63707df2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.3-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 61b4fd26839d2e6f8e20940d02cf7df09889f6e5e20b3ad48a4b20a5acf3c6f5
MD5 24bd5c47e89faffbe1932a9bf72752d9
BLAKE2b-256 a2dade2bb7674404ee911c29be9d6b08c7793cdfcf41b210b85e935341a04a13

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