Skip to main content

Prince: convert HTML with CSS to PDF. Bundles the Prince engine - no separate install required.

Project description

prince-pdf

Python packaging of Prince, the HTML-with-CSS to PDF engine. The wheel bundles the Prince engine for the current platform — no separate installation, no network access at install or run time.

pip install prince-pdf
import prince_pdf

prince_pdf.convert("document.html", "document.pdf")

pdf_bytes = prince_pdf.html_to_pdf("<h1>Hello</h1>")        # in-memory
pdf_bytes = prince_pdf.markdown_to_pdf("# Hello")           # Prince 17+

The package also puts prince on PATH, so the full command-line interface works as documented:

prince document.html -o document.pdf

python -m prince_pdf also works anywhere the package is importable, even when the script directory is not on PATH.

Prince is free for non-commercial use (output carries a watermark on the first page until a license is installed). Commercial use requires a license from YesLogic. Point the engine at your license file with the PRINCE_LICENSE_FILE environment variable (preferred — it survives reinstalls), or install it at the path returned by prince_pdf.license().

Supported platforms: Linux x86-64 and ARM64 (glibc), musl/Alpine ARM64, macOS 10.13+ (universal), Windows x64 and ARM64. On Linux x86-64 the engine additionally needs the system fontconfig library — in minimal containers, apt-get install libfontconfig1 (it usually arrives with fonts anyway).

Names

One package, three names: install it as prince-pdf, import it as prince_pdf, run it as prince. Note that pip install prince installs an unrelated statistics library, not this package.

Python API

  • prince_pdf.convert(inputs, output=None, args=()) — convert one or more files (HTML, XML, SVG; Markdown with Prince 17+; a list is merged into one PDF), with the format detected from each file. Extra command-line options go in args, e.g. args=("--javascript",). Returns the output path, or the PDF as bytes when output is None.
  • prince_pdf.html_to_pdf(html, output=None, args=()), prince_pdf.markdown_to_pdf(markdown, ...), prince_pdf.xml_to_pdf(xml, ...) — convert a document given as a string or bytes, without temporary files. Combine with output=None for fully in-memory conversion. Markdown input requires a bundled Prince 17 or later (pip install --pre prince-pdf while 17 is in pre-release); on older engines markdown_to_pdf raises an error saying exactly that.
  • Failures raise PrinceError carrying .returncode, raw .stderr, and .messages — the engine's diagnostics parsed into Message(severity, location, text) tuples. Engine warnings during successful conversions are emitted on the "prince_pdf" logger.
  • prince_pdf.run(*args, **kwargs) — invoke the engine with raw command-line arguments; kwargs pass through to subprocess.run().
  • prince_pdf.command(*args) — the argv list that would be run, for use with external process tooling.
  • prince_pdf.executable() — path of the bundled engine binary.
  • prince_pdf.version() — the engine's version string.
  • prince_pdf.license() — the default license-file location inside the bundle (prefer PRINCE_LICENSE_FILE, which survives reinstalls).

Troubleshooting

  • Missing or wrong fonts in minimal containers: the wheel bundles the engine but uses the system's fonts. Install some, e.g. apt-get install fonts-dejavu fontconfig (Debian/Ubuntu) or apk add fontconfig ttf-dejavu (Alpine).
  • libfontconfig.so.1: cannot open shared object file (Linux x86-64): install the system fontconfig library, e.g. apt-get install libfontconfig1 — installing fonts as above also provides it.
  • Watermark on the first page: expected without a license — the engine is fully functional for evaluation and non-commercial use. A purchased license (via PRINCE_LICENSE_FILE) removes it.
  • Documents referencing remote resources: fetching http(s) images or stylesheets requires network access at conversion time; self-contained local files need none.
  • Diagnosing failures: PrinceError.stderr carries the engine's warnings and errors; add --verbose (or -o plus --log=FILE) for more detail.

How this repository works

This repo contains no Prince binaries and no engine source — only packaging.

  • versions.json — the release manifest: for each wheel platform tag, the princexml.com artifact URL and its SHA-256. Wheels are built only from artifacts that verify against this manifest, so a commit of this repo fully determines the bytes that reach PyPI.
  • src/prince_pdf/ — the wrapper module and prince console script. At build time the engine's installation prefix is bundled as prince_pdf/_bundle/, and the wrapper invokes _bundle/bin/prince --prefix=<bundle> (the same thing the shipped launcher script does).
  • build_hook.py — hatchling hook that sets the wheel's platform tag and pulls in the staged engine tree.
  • scripts/build_wheels.py — download → verify → stage → build, for one or all platforms.
  • scripts/update_versions.py <version> — regenerate the manifest for a new Prince release: downloads the artifacts, computes checksums, and scans the Linux binaries' GLIBC_* symbols so the manylinux tags stay honest.
  • .github/workflows/wheels.yml — builds all wheels on one Linux runner (repackaging only, no compilation), smoke-tests each wheel on its real platform (including installing and running with networking disabled), and publishes to PyPI via trusted publishing when a v* tag is pushed.

Building locally

pip install build hatchling
python scripts/build_wheels.py --platform macosx_10_13_universal2
pip install dist/prince_pdf-*.whl
python tests/smoke.py

Releasing a new Prince version

  1. python scripts/update_versions.py 17
  2. Review the diff, commit, and push a tag matching the new package version (v17.0.0).
  3. CI builds, tests, and publishes to PyPI. Packaging-only fixes between engine releases use PEP 440 post-releases: 17.0.0.post1.

Pre-release builds map to PEP 440 versions that pip hides from ordinary users (installed only with --pre or an exact version pin):

  • Betas: python scripts/update_versions.py 17b1 → package 17.0.0b1.
  • Dated builds: python scripts/update_versions.py 20260630 --dev-of 17 → package 17.0.0.dev20260630. The --dev-of mapping is required — a raw date used as a version would sort above every real release forever. .dev versions sort before the release they lead to (17.0.0.dev20260630 < 17.0.0b1 < 17.0.0), so once 17.0.0 ships, dated builds must target the next release: --dev-of 17.1.
  • The pre-release channel may build for a different Alpine range than the stable channel; pass --alpine-oldest 3.21 accordingly.

Publish selected milestones, not nightlies: each release uploads ~200 MB of wheels against PyPI's default 10 GB per-project quota. Old .dev releases can be deleted from PyPI to reclaim space, and quota increases can be requested if needed.

One-time setup on PyPI: create the prince-pdf project and add a trusted publisher for this repository (yeslogic/prince-python, workflow wheels.yml, environment pypi), and create the pypi environment in the GitHub repo settings (protect it with required reviewers). No sdist is published — there is nothing to build from source.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

prince_pdf-17.0.0.dev20260630-py3-none-win_arm64.whl (13.6 MB view details)

Uploaded Python 3Windows ARM64

prince_pdf-17.0.0.dev20260630-py3-none-win_amd64.whl (15.4 MB view details)

Uploaded Python 3Windows x86-64

prince_pdf-17.0.0.dev20260630-py3-none-musllinux_1_2_aarch64.whl (15.5 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

prince_pdf-17.0.0.dev20260630-py3-none-manylinux_2_25_x86_64.whl (15.9 MB view details)

Uploaded Python 3manylinux: glibc 2.25+ x86-64

prince_pdf-17.0.0.dev20260630-py3-none-manylinux_2_25_aarch64.whl (14.7 MB view details)

Uploaded Python 3manylinux: glibc 2.25+ ARM64

prince_pdf-17.0.0.dev20260630-py3-none-macosx_10_13_universal2.whl (27.4 MB view details)

Uploaded Python 3macOS 10.13+ universal2 (ARM64, x86-64)

File details

Details for the file prince_pdf-17.0.0.dev20260630-py3-none-win_arm64.whl.

File metadata

File hashes

Hashes for prince_pdf-17.0.0.dev20260630-py3-none-win_arm64.whl
Algorithm Hash digest
SHA256 b0ab02f0605fc47064f960d752439ceda144c519c9fec67013a3fcaf35ef0dce
MD5 616481e53e3f78e691100c41e2b4b5cb
BLAKE2b-256 c2c8982ebf130ad580acde70da618f9e3594d24799f1265217976c9145659669

See more details on using hashes here.

Provenance

The following attestation bundles were made for prince_pdf-17.0.0.dev20260630-py3-none-win_arm64.whl:

Publisher: wheels.yml on yeslogic/prince-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prince_pdf-17.0.0.dev20260630-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for prince_pdf-17.0.0.dev20260630-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 5c49f2bcfd6cdb39f65c73968fd7d1d1d5b6c31c1ba9c1a8b824d52cf432da3f
MD5 f8344eed32d295e647ec33434bc0cc17
BLAKE2b-256 8ea7904e92f534afcb0436e1ea5e5caf845fb905ddb0ba45f7dfc740e71d94c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for prince_pdf-17.0.0.dev20260630-py3-none-win_amd64.whl:

Publisher: wheels.yml on yeslogic/prince-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prince_pdf-17.0.0.dev20260630-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for prince_pdf-17.0.0.dev20260630-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 0a585abc05f4c3d81bc070dbd5ac72626629b7968933bb7f3328615d3f0a0803
MD5 7ba3e0078774c05b1824dff46e8fff52
BLAKE2b-256 49b82a3e016a57456a811870591fb2c5d39f3ba72e848d99bde5424aeb457752

See more details on using hashes here.

Provenance

The following attestation bundles were made for prince_pdf-17.0.0.dev20260630-py3-none-musllinux_1_2_aarch64.whl:

Publisher: wheels.yml on yeslogic/prince-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prince_pdf-17.0.0.dev20260630-py3-none-manylinux_2_25_x86_64.whl.

File metadata

File hashes

Hashes for prince_pdf-17.0.0.dev20260630-py3-none-manylinux_2_25_x86_64.whl
Algorithm Hash digest
SHA256 bd6116b9a93fdc99e25e40fb0b067d16f8c1684dec3c9ed235e305701676e684
MD5 fe8364807853fa180ef467375ef50c2c
BLAKE2b-256 c0da1d4829e236c6433aa8c6b64a12655dcd311743d08f6174856b9c4af08acb

See more details on using hashes here.

Provenance

The following attestation bundles were made for prince_pdf-17.0.0.dev20260630-py3-none-manylinux_2_25_x86_64.whl:

Publisher: wheels.yml on yeslogic/prince-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prince_pdf-17.0.0.dev20260630-py3-none-manylinux_2_25_aarch64.whl.

File metadata

File hashes

Hashes for prince_pdf-17.0.0.dev20260630-py3-none-manylinux_2_25_aarch64.whl
Algorithm Hash digest
SHA256 0ea8b40fd0c5d411e0256c5822ef98e6172e8843ba002575ada3c3589ebaffb2
MD5 8c265e06308a06f9ced545c2b8d4b2c0
BLAKE2b-256 2306381e94a8e24803701630c7c8f1cbf1c831ad67f9d5d9b4cfc2fcaf631b5f

See more details on using hashes here.

Provenance

The following attestation bundles were made for prince_pdf-17.0.0.dev20260630-py3-none-manylinux_2_25_aarch64.whl:

Publisher: wheels.yml on yeslogic/prince-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prince_pdf-17.0.0.dev20260630-py3-none-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for prince_pdf-17.0.0.dev20260630-py3-none-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 31f45a5127f4ba4fec1806c51297ec2c2f90c57422cabbc932a30375da897358
MD5 22f33d2e092cd01f21d950b38a56be05
BLAKE2b-256 2c53cd1475fd36bb46b0bc18b4862023efcc2c9d5b8e5cf1b501aa5b0cbae01e

See more details on using hashes here.

Provenance

The following attestation bundles were made for prince_pdf-17.0.0.dev20260630-py3-none-macosx_10_13_universal2.whl:

Publisher: wheels.yml on yeslogic/prince-python

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