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

Uploaded CPython 3.8+Windows x86-64

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

File metadata

  • Download URL: turbo_html2pdf-0.2.3.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.3.tar.gz
Algorithm Hash digest
SHA256 98ecc6508c0511b208ee74baef228d76d2030c60d8a80f90c0307031c715f661
MD5 30dfcb1e4660bf78c84b1743884fc6e0
BLAKE2b-256 f7be1ab0ddf3de27ae3af439a33e2816c64372f6805ac130d58c354dafe09019

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.3-cp38-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 479df4202f84695a58e169d3bf32281b51f7bcf542fc631a8f4b77b587c0a926
MD5 a68003c083b25825e5d1501ff1a41a4f
BLAKE2b-256 b9359ae1098beca4be01108e535ccf706f706e0702401824496a7a26ae917dac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 97248821dc382bd2081a2220c9c362cea701c3a0dd26d3ab049100c2ef4d7860
MD5 6479d3d4ade7aae20c5bff82215f366f
BLAKE2b-256 b4e8d1974d32c625c6bd3796fb1f45278d8321bca0899733b964f1e83d709e1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.3-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 582d276ebfddd0e533b07c485523ff1e7f861a5644a420e3dc397096276121e0
MD5 b3369120a38009fe7b94c6ff4d179ddb
BLAKE2b-256 624eacb163cc8ea42f71ed27a2dd1e448517d88440e418325e524e86679de785

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for turbo_html2pdf-0.2.3-cp38-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 884f86ab5453d1621590ad965394c64b5abff91ecf15eb2887130f285aea5a4d
MD5 98b5d34a45a7551d6419ef178bc97378
BLAKE2b-256 e1adb5ef97a793117ea0d5ca158edbef76f3960ba1ac2f1dc82ce15c7ee076ba

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