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.13.0.tar.gz (728.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.13.0-cp39-abi3-win_amd64.whl (7.2 MB view details)

Uploaded CPython 3.9+Windows x86-64

pyfulgur-0.13.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.13.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (7.0 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.17+ ARM64

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

Uploaded CPython 3.9+macOS 11.0+ ARM64

pyfulgur-0.13.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.13.0.tar.gz.

File metadata

  • Download URL: pyfulgur-0.13.0.tar.gz
  • Upload date:
  • Size: 728.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.13.0.tar.gz
Algorithm Hash digest
SHA256 2be92728ebc34f6ebc17ad53ca4bf23bcffe1b3a4e2dafced013d998ed565351
MD5 83c32901516eff7caaa98a529daff3b2
BLAKE2b-256 4a88089323d794f541f146d822251ee86b0106f9f0cdff21d1d41bcb2cf9832c

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyfulgur-0.13.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 7.2 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.13.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 e024d02dde295bd3a3e88baa53573ddcddf302dda848433e7abd31dc4782660e
MD5 36db26768cbc288293eda244911b5559
BLAKE2b-256 ecdd23e36b60034233cdbe2fb3bb8e040323af587f98b219adb06bead8fefb09

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.13.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fefbe89c157465cd07cb8c8fd56d55ae3c795a09156273ce1d7a5a5b7dcef173
MD5 f0572d349277ad38283fddc46ae90eff
BLAKE2b-256 027b9bd7a587878da4aaa8e442b1df97c6e5809f413b4c76dec7c1a4ac2fa584

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.13.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d1b24e56fff6dac943a3d5cb8e4456c9887afc20ef25f20dd421a7c38716c211
MD5 0dcd470e2f36bc93ef9cf9cc31464361
BLAKE2b-256 7fc93564a79528ffbbfe72bc164c4e6bc8639114b7ceb481134ea6fa7af17ba2

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.13.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 cd624e3d68ed1bf856e362030f1caeb86321e9f0cf5efc8614a3265bee3ca7ec
MD5 7da8f2337bd0f9f1304ee28704ac4954
BLAKE2b-256 9166f1168629224b1c8b15f0e24a1a096f343f2d3ae1936668df05caa7d51eb5

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.13.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 02b4154abff8154c08523cb18a9c60cf17972622c3d62c259a9553f278a9590e
MD5 dd4dcfe51f7c1d7b465378fd53563d92
BLAKE2b-256 ffc2de04bfedf6c362ffbdd7e46f504bf034cbd57293bbe8eb23270b98541df0

See more details on using hashes here.

Provenance

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