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

Uploaded CPython 3.9+Windows x86-64

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

Uploaded CPython 3.9+musllinux: musl 1.2+ ARM64

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

Uploaded CPython 3.9+macOS 11.0+ ARM64

pyfulgur-0.31.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.31.0.tar.gz.

File metadata

  • Download URL: pyfulgur-0.31.0.tar.gz
  • Upload date:
  • Size: 932.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.31.0.tar.gz
Algorithm Hash digest
SHA256 11d12cbca7c46017c2c11b646d0d1850629834d8f52e9735f3ee65177a835897
MD5 f8349e050b1c6ca653673ea0e04aefff
BLAKE2b-256 c08851ba180ac9f09b0915026ad024d534eefd1f439fe804fd39b6938400504b

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: pyfulgur-0.31.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.31.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 65c0d8dc3e21dc67e0e45a157ee6e0d233b03f1d2f00ca65c76b209fdd863c2d
MD5 9e23b7c7973796ce7ef5704aedfd3fa2
BLAKE2b-256 0045ccc9df82136fe24503a7f7a3d63f6bd5771db7b7a2325e821c645cb146dd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.31.0-cp39-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 80db192e8ad453f4501d9bc74745e75fa03dba78eec107c4801b3832f815d482
MD5 4004f9af67060037c3bb7688a0d9b6af
BLAKE2b-256 18b7061232dc861ce323b51d318ce6df3321021eaf3e8859a1e95afcf9c0b39c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.31.0-cp39-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 7466473cfe580de41ced62bcfd2dae060862b5da06a739dcdc9a8297c9d5fd3f
MD5 66da268cdb79b8e20f1dd921da9e3de9
BLAKE2b-256 e2a2410f5d3359edc756f02e99068ead9fc29cda29f6224fa37a641c51607acb

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.31.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 03b20a282eed784de41e84f5fe12e30aaeda513c42e5e2e0f306346e37b6df78
MD5 910b1d7efccd8c00516a713f7f47069f
BLAKE2b-256 922d9918b9645d1fcfbfaeda4011049adb5d2e48e4b5e86c6e1132c5c4417d5b

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.31.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7d22d3306f7270397198b1b67db902e6a1494db01f7d3ec0a34bf44a4f58bdef
MD5 f04e8c597789deba95f695f62810ace0
BLAKE2b-256 31249acdaab6476ee115097e36e4d8bf1cf98c6dea43224f50581a0a12b1b7c9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.31.0-cp39-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e0cb48f99d5ff876521e6d1795bf3d46c07a56fc5d20174c29474573f68712bd
MD5 2652f0635fb9c3e992052654d502f4d2
BLAKE2b-256 bc53e753ac2cacb3384b98ca209d087984a6cfb02d2bde4baf85467e87ae147f

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for pyfulgur-0.31.0-cp39-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 ea32ab4ebdaf9e65edfe87426e9d6fd73669ec7d158c0777d0d7415450b3ab80
MD5 b825bdb68d45a93e43e0570bee2cdfae
BLAKE2b-256 043d04514e33692674b74847c1936cd76f1420b1e4116b5e676c076929aeb20f

See more details on using hashes here.

Provenance

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