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.28.0.tar.gz (920.5 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.28.0-cp39-abi3-win_amd64.whl (7.3 MB view details)

Uploaded CPython 3.9+Windows x86-64

pyfulgur-0.28.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.28.0-cp39-abi3-musllinux_1_2_aarch64.whl (7.3 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

pyfulgur-0.28.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.28.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.28.0-cp39-abi3-macosx_11_0_arm64.whl (6.8 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

pyfulgur-0.28.0-cp39-abi3-macosx_10_12_x86_64.whl (7.1 MB view details)

Uploaded CPython 3.9+macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for pyfulgur-0.28.0.tar.gz
Algorithm Hash digest
SHA256 a3d4c85504ee39b5da2c4e93afc9328b195f9813c23f973776353802c989903a
MD5 e4e7e54dc542459fbf6804272f859c15
BLAKE2b-256 bb8ba5c01b44db4f1739c8cf1f233f3dea6e1671a5cf22cfd70ad5cd54cd9a3a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.28.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.28.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: pyfulgur-0.28.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.28.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 6c82fa45079ce4506e82e617a4ec7fe60e3a71d874067c3b92e2e2f4b20abb8c
MD5 b86592327a455ddadbb8d6a360071d9e
BLAKE2b-256 892c083d66a8807ceb861f8dfd125e6469070a567c3d5374220e76923cdced46

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.28.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.28.0-cp39-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for pyfulgur-0.28.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 125101dbd22d906f222868a746c6010004250d6545b0308d91d9a4a29dcff041
MD5 a471a2cfb2a2cf4977faff260df28a03
BLAKE2b-256 d7a86571a4a0bae6b71d2070c7a214a2ff5613e0bf2de43f123331124f8d64bb

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.28.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.28.0-cp39-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for pyfulgur-0.28.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 85e43ca7b5d30ca11523b72f474e9bc99fdaa43dee47f2d4cb936f6c9963aab3
MD5 7da52b7cc2dd61e56886b3cb6acc8e28
BLAKE2b-256 e2c003913e4740d89656071bc3a070ccb45d062866c14e50c638134cefa0618d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.28.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.28.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pyfulgur-0.28.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a430d671cebefd8b3b028bb0844f3a3c8b99cd24ae6939750af5a6f09281515b
MD5 903812b2812e725dd43587a671293540
BLAKE2b-256 8eabc60eb9b08718ac970500655b6ba4fe6b82e8cf57836b4e0c3f8782638c19

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.28.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.28.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pyfulgur-0.28.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 86c41421b66c635c31a4b77bf48eaa1a47bbd460790447a195fd9923e7dd7986
MD5 a942409e09f7751fd4817a16207b4bfc
BLAKE2b-256 59edac6923f800cf8b973b971d1cab2dbfdeaa13bbf7f79e6bf7cf202788b30c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.28.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.28.0-cp39-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pyfulgur-0.28.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 734e6e3675831c3cf1ca653a5e2ba6deb11a7bad346fab9417f2858976e3b61c
MD5 b2c007de042874bafc467f587ec630b6
BLAKE2b-256 46caf98309ebe0cec77336b53b141f8e31e7a387bb08a65e674985721bc1ddd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.28.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.28.0-cp39-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pyfulgur-0.28.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 f3f8215b30fbcabb79cabb7aef5602b869f10ada5429f743c309d1cbfa44a248
MD5 b89bcc47640ccf5331c324c4bb21e5e8
BLAKE2b-256 0e140c8d2fc5ef1ce355a7b36d657030250c27689e465a94768c793762d4a128

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyfulgur-0.28.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