Skip to main content

Python bindings for fulgur — offline HTML/CSS to PDF conversion

Project description

pyfulgur

Python bindings for fulgur — an offline, deterministic HTML/CSS to PDF conversion library written in Rust.

Status

Alpha (v0.0.2). Core Engine / AssetBundle / PageSize / Margin / render_html API is available. Batch rendering, sandboxing, and template engine wiring are planned for later releases.

Install

Note: v0.0.2 is an early alpha. Pre-built wheels are not yet published to PyPI; install from source for now.

# From a checkout of the fulgur repository
pip install maturin
maturin develop --release -m crates/pyfulgur/Cargo.toml

Pre-built wheels for manylinux / macOS / Windows will be published in a later release.

Quick start

from pyfulgur import AssetBundle, Engine, PageSize

bundle = AssetBundle()
bundle.add_css("body { font-family: sans-serif; }")

engine = Engine(page_size=PageSize.A4, assets=bundle)
pdf_bytes = engine.render_html("<h1>Hello, world!</h1>")

with open("output.pdf", "wb") as f:
    f.write(pdf_bytes)

Builder style:

engine = (
    Engine.builder()
    .page_size(PageSize.A4)
    .landscape(False)
    .title("My doc")
    .assets(bundle)
    .build()
)
engine.render_html_to_file("<h1>Hi</h1>", "out.pdf")

API surface

  • Engine(**kwargs) / Engine.builder()EngineBuilder
  • Engine.render_html(html: str) -> bytes — render to PDF bytes (releases the GIL)
  • Engine.render_html_to_file(html: str, path: str | os.PathLike) -> None — render to a file
  • AssetBundle: add_css, add_css_file, add_font_file, add_image, add_image_file
  • PageSize: A4, LETTER, A3, custom(w_mm, h_mm), .landscape()
  • Margin: Margin(top, right, bottom, left), Margin.uniform(pt), Margin.symmetric(v, h), Margin.uniform_mm(mm)
  • Exceptions: FileNotFoundError, ValueError, pyfulgur.RenderError

Type stubs

pyfulgur ships PEP 561 type stubs (py.typed + __init__.pyi) so mypy, pyright, and IDEs can type-check call sites against the native API. Docstrings live in the Rust source and are exposed via __doc__ for help(), Jupyter ?, and griffe / mkdocstrings inspection.

Known limitation: blitz parse-error noise on stdout

The underlying blitz-dom parser writes non-fatal html5ever parse errors directly to the process's stdout via println!. These fire for browser-tolerated but technically invalid HTML — documents without a <!DOCTYPE>, missing <html>/<body> wrappers, or structural quirks that browsers silently auto-correct — and show up as ERROR: ... noise in Jupyter notebooks or any environment that captures stdout. The PDF bytes returned by render_html are not affected; only the caller's terminal is polluted.

pyfulgur intentionally does not redirect fd 1 from inside the binding: process-wide fd manipulation in a multi-threaded library context races with concurrent render_html calls from other threads (mixed suppress / non-suppress callers would silently lose stdout during a suppressed window). Correctness and parallelism take priority over cosmetic stdout cleanliness.

If you need clean stdout:

  • Redirect at the caller side with a Python contextlib.redirect_stdout for Python-level writes, or os.dup2 for fd-level writes. This keeps the fd manipulation scoped to your own call site where you can guarantee single-threaded use.
  • Run renders in a subprocess via multiprocessing (each worker has its own fd 1).
  • Use the fulgur CLI (which handles stdout isolation internally) invoked via subprocess.run when cold-start cost is acceptable.

A wrapper-style Python package that shells out to the fulgur CLI (clean stdout, parallel via process isolation, no native build required) is on the roadmap as a complement to this native binding.

Links

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

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

pyfulgur-0.36.0.tar.gz (949.7 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pyfulgur-0.36.0-cp39-abi3-win_amd64.whl (7.3 MB view details)

Uploaded CPython 3.9+Windows x86-64

pyfulgur-0.36.0-cp39-abi3-musllinux_1_2_x86_64.whl (7.7 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ x86-64

pyfulgur-0.36.0-cp39-abi3-musllinux_1_2_aarch64.whl (7.2 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

pyfulgur-0.36.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.5 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ x86-64

pyfulgur-0.36.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.1 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

pyfulgur-0.36.0-cp39-abi3-macosx_11_0_arm64.whl (6.7 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

pyfulgur-0.36.0-cp39-abi3-macosx_10_12_x86_64.whl (7.0 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

Details for the file pyfulgur-0.36.0.tar.gz.

File metadata

  • Download URL: pyfulgur-0.36.0.tar.gz
  • Upload date:
  • Size: 949.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pyfulgur-0.36.0.tar.gz
Algorithm Hash digest
SHA256 494ba842776aa9894e179ac00851f59db596f3cf3ba14268257dedced3f4ddfd
MD5 075abcc986258d943c3a2d19559f7484
BLAKE2b-256 d616f008fe3614f21b18bbe2023b9537ca0cd14cf5a8873f8f479ca4dcf615ab

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.36.0.tar.gz:

Publisher: release-python.yml on fulgur-rs/fulgur

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyfulgur-0.36.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: pyfulgur-0.36.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 7.3 MB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for pyfulgur-0.36.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 50e6caf968f1bc4d334b046e4d01ad17b518393c66d0367aeda72f3a91d51382
MD5 8af4b74ba97b26624974e8f1ae370fa3
BLAKE2b-256 25ad2ffe7d5e74b002b9f0a482cc0b131bce549a7913f0bf61a8ed87fb85390f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.36.0-cp39-abi3-win_amd64.whl:

Publisher: release-python.yml on fulgur-rs/fulgur

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyfulgur-0.36.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyfulgur-0.36.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 8dfe19737783835cae66bb88f97fc6904900f04d1d6b3527dfcc43a0b90b5ca6
MD5 64f2554b82a18258de3aef8b0c44ed32
BLAKE2b-256 56861ade868ed8fce0a13812e25d43953fe9f494b440705a5f6965a19e838ecb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.36.0-cp39-abi3-musllinux_1_2_x86_64.whl:

Publisher: release-python.yml on fulgur-rs/fulgur

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyfulgur-0.36.0-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyfulgur-0.36.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 9a3d9a3afb3928173cb89d2f8b01ffaa446fe93bb5202420e1ecfae995dad9d7
MD5 86364cf340b92d8d532b47f376021272
BLAKE2b-256 c8b3dbec916565f6d64dac6e31d180d6f3d801f3030e9f02da875106b61c51a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.36.0-cp39-abi3-musllinux_1_2_aarch64.whl:

Publisher: release-python.yml on fulgur-rs/fulgur

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyfulgur-0.36.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyfulgur-0.36.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0749c37b8c2c5565b6e59e3a38b6f52ffc6464b405fe586a1e7bbe3c6f76a474
MD5 3f16268c8e4dbb92cfa83b45f92c8003
BLAKE2b-256 f98174a2cacc7b35dd0ffd662dc8526005809b7c4e5ce5e189407c02aedecccd

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.36.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release-python.yml on fulgur-rs/fulgur

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyfulgur-0.36.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyfulgur-0.36.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f41d05cb9384c486085f269b81f470774d3e6e8e923ff09b045e5c0be0a69ec6
MD5 2ce7b6e981f443e26da38c1ad41fa12a
BLAKE2b-256 e971770b1881586403d97f3c2eebb49963bd8766034e6b6e8620897e339fe400

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.36.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release-python.yml on fulgur-rs/fulgur

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyfulgur-0.36.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyfulgur-0.36.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 930552a712b573d7a150bdbce722d0ddf59d2627f7d0591bc87b8e36ab222b2a
MD5 2613b890db1bdae58b762a52f832e684
BLAKE2b-256 f789d632e9d57ec64ed8fef41a8ce7f8659af9fca3dbb7632439dfc85ad379ca

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.36.0-cp39-abi3-macosx_11_0_arm64.whl:

Publisher: release-python.yml on fulgur-rs/fulgur

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyfulgur-0.36.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyfulgur-0.36.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 dc492ce4fb1a9e3c735e81d23bf84d1846c9b493bf145e8a6eef6d6e8795c94f
MD5 8418d8f572a298bd0a487de69c5acdbb
BLAKE2b-256 4e2d60ef743458f9e4b64658fb7c920f4dc412d0d79bc349e3d4e9b319740be5

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.36.0-cp39-abi3-macosx_10_12_x86_64.whl:

Publisher: release-python.yml on fulgur-rs/fulgur

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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