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

Uploaded CPython 3.8+Windows x86-64

turbo_html2pdf-0.1.4-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.4-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.4-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.4.tar.gz.

File metadata

  • Download URL: turbo_html2pdf-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 02e8d71b55019d431a629f9f448b0769aaa68436c14ab1ff7bffcf523f17f261
MD5 0c9867bc8d392026959b00689113e564
BLAKE2b-256 5a96eeefa07a339ac04b6ebaf49dbca19f9ed15dfc94b1c503f6eadbc12f74f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.4-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 218516207a6cf1fd663a7dd4691a1d3e2ed78c7e025ac3434aefa2f0d44e9400
MD5 e91df85d6ad5a0ffa65943870c0c35ce
BLAKE2b-256 fb1c164ed37416907e3696f903507c4f3d503ab534f05f44fae686cf246ed4c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.4-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2d3cbad3ad93c9e996f06a64277a80109b9e2772d28dbdb69608366bd2f19f55
MD5 706eb0357e87ab8493be4d828beabf81
BLAKE2b-256 43f3ad94c774d4291179a9986f7a998d488cc8175e923dc36411c32802c03e15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.4-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 36b74aaed272b6bb253881e7de9998709497da1998ff8a9e61985dfc7e10a3ef
MD5 a919e07a2ada9f8aae9526a4f851d5f3
BLAKE2b-256 ac929e4873361a11b4ee065bdf55888efb3524f868441417d88ec64628b28c57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.1.4-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fa78489e7ef55e88a2de33d0935398c1a0a5b8fb5f1c5eca63e2f017cdb496ac
MD5 189748e872647935b2f8515bbbe132e2
BLAKE2b-256 5ecfbe253ac03c97a4f53082f20d31e66ac9b6e4ab3fe569d71d10a0d23c8015

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