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

Uploaded CPython 3.9+Windows x86-64

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

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

pyfulgur-0.25.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (7.6 MB view details)

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

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

Uploaded CPython 3.9+macOS 11.0+ ARM64

pyfulgur-0.25.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.25.0.tar.gz.

File metadata

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

File hashes

Hashes for pyfulgur-0.25.0.tar.gz
Algorithm Hash digest
SHA256 ab7b8d594761c4fda1e2da9d9f1622774f40cbdb878a8d1c1b242f9326918e51
MD5 5b6c3075af78e80172da4c2a0dde1112
BLAKE2b-256 14a7fde63c31b11fffcb6650326cb81e01c6d08836da4bb33ff3df65737e6b42

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyfulgur-0.25.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.25.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 48d90cb14e352d62ab5954351e5d750649d669bc5477d7a562c17e517d4e6aef
MD5 60395613644297fc59f298a8e0888217
BLAKE2b-256 4c9f6f15ab964f3a3694617f04417c74bbe6e078e085703b909073e557ad2b51

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.25.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 d8268ddae76bfa6598d004b2695d55161ddaa0d990a2bb546e10a06d1aefca13
MD5 cf8e05dc892e7cb49cf28e9d0fbd7933
BLAKE2b-256 1af2b30279df3b14a936f072d42d3b859ed1dbf875837f68149810541c41feff

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.25.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 27c998174bfff0abc5758e4206b544ac87c2da537647ad97294724de7a9e581f
MD5 852dbd618eace18507e998cfe89ace8a
BLAKE2b-256 552e401cf639e2e45cf900cc7d4488b4411100849ef3977b01eca6ebf30e5f63

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.25.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c7d83c927e748cf6c8853a19bfb24ff1684537f6f5b42aa66db48d48576fef3b
MD5 eaf63b6d3db8aff7161397d010a08d63
BLAKE2b-256 91e72cd422bf1262c303ae3df567a6e2e17ab80338ad7ba8b0031e7536faf865

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.25.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 81b120ee2b517dcc8b5934fd100c47315596067cd0f348d50561966095440152
MD5 58e5b498c883d4738c8c4eb195274197
BLAKE2b-256 960a25ae8e0dc9387eb8c49ca5af5fc592c88065429843ab135ba14f2d0ac0c1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.25.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 402677bd6ad664526debb8afbd3565b9d7281873af3b4e6713251733241b7685
MD5 2c4996b6b8e2685fcf0df9e9234f5581
BLAKE2b-256 11eb4bf136bee1dba12bf0e56fe8c46b3b822abde6503f058bbbc55f8a80209b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.25.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 af7aa4f85ca0f55946d443ff3a5836cc1810e610fa59c75bcd40a1373f1ffe39
MD5 fe916cbd27d75c8107f0261172a0ebd1
BLAKE2b-256 578e5515d10cde1567abb654d127c84c679c5c7a32afa8cc1c3dd3df5a194632

See more details on using hashes here.

Provenance

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