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

Uploaded CPython 3.9+Windows x86-64

pyfulgur-0.37.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.37.0-cp39-abi3-musllinux_1_2_aarch64.whl (7.2 MB view details)

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

pyfulgur-0.37.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.37.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.37.0-cp39-abi3-macosx_11_0_arm64.whl (6.7 MB view details)

Uploaded CPython 3.9+macOS 11.0+ ARM64

pyfulgur-0.37.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.37.0.tar.gz.

File metadata

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

File hashes

Hashes for pyfulgur-0.37.0.tar.gz
Algorithm Hash digest
SHA256 4eb665ddc59edbd0fa843be5e632250ec6458f8e04650fa1fe15b347635d18be
MD5 22360149928f9da330368bdf4d4bc402
BLAKE2b-256 1a3ee97165d6fcee4e8a85aaf7a1b1bd09f9fe8f98b411bf12e04b975294af36

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyfulgur-0.37.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.37.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 ce17742e1f973ca3909f334d15bad62f839b6657e4dfe522f8c9440fad1853e7
MD5 882660313458b2ca7a824ee1dd2fca4c
BLAKE2b-256 b369e3081ebbd49cff9b3bff6beff501d18aa9680a05d48754850890266fa083

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.37.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 55b98e9c3f90896fbb58e179ee5018119fcd42cced047a368df20134b720b4e8
MD5 8309487026bbc98e7bff5db2a6285d09
BLAKE2b-256 50eb1418f3f563274188221fbd146f4690511aa1f6d18132d2a4605d8082f6c0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.37.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7b2d413034bf093decbb43dc31957868fa33d5d3e38f7610d7d71e50dad786b2
MD5 1c2bf0f3f0a4264efece522c16885421
BLAKE2b-256 f415a3b8fa15846b66b4ebe8cf7f7f795af9eb750778ad4a52d24645ef0bdb00

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.37.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8894cc1382b6597164bc49a0980b98469dfb9b0de6f3c3ab5e510a786607f9ea
MD5 ed977c4d91e3b34c0c2f75cd9c4b2300
BLAKE2b-256 9df77efe6307091fba2c02e25f3a57e51c90d216804d5322323cbbf2c6d14a8c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.37.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 039b82e820915fe26aafa79b3fe7146c0b2d45fe288fadb908b9f533799e8ad7
MD5 f671a26952d5705942997f0040b03f6b
BLAKE2b-256 79d722f8cfcdbfeb417bda8d4686aaa10d1c46db845e1de4bb0a50b55d38bdc1

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.37.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 fd39034091905a62679c9941220e77f0e1669f0e79cdc585136831cf91867e01
MD5 be01a9b3e1f94aa2b9eec5495ad516f1
BLAKE2b-256 95f0d443a417c30ad73980c2d653012cbe04b5b9e80225db5b6475e666f26c0d

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.37.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 725611091bb8ce3fe152a6c8fdcb6165e25b611ccfad16f9b8395489485ddac5
MD5 97606be1ac91b63225c88a8217a52c11
BLAKE2b-256 8040c3bbce5341927b0be41bb17a1fee4d3fa05f76badb3ea1fd269c863db9aa

See more details on using hashes here.

Provenance

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