Skip to main content

PDF editing and rendering for Python, powered by Rust (lopdf + hayro). MIT, zero dependencies, lightweight wheels.

Project description

pylopdf

日本語版 README はこちら

PDF editing and rendering for Python, powered by Rust — lopdf for editing and hayro (the pure-Rust PDF renderer adopted by typst) for rendering.

MIT licensed, zero runtime dependencies, lightweight wheels. Covers the common pymupdf use cases without the AGPL.

Why pylopdf?

pylopdf pymupdf pypdf pypdfium2
License MIT AGPL / commercial BSD Apache/BSD
Wheel size ~3.5 MB ~40 MB+ small (pure Python) ~8 MB
Editing (merge / split / metadata) limited
Rendering (PNG / SVG) ✅ (PNG)
Text extraction ✅ (basic) ✅ (advanced)
Implementation pure Rust C Python C++ (PDFium)
  • Fits size-constrained environments such as AWS Lambda
  • Safe for commercial projects that need to avoid the AGPL
  • abi3: one wheel covers Python 3.10–3.14
  • API modeled after pymupdf

Limitations: no precise layout analysis, no annotation/form editing, no encrypted PDFs. Use pymupdf if you need those.

Install

pip install pylopdf  # (after PyPI release)

Building from source (requires a Rust toolchain):

uv sync

Usage

import pylopdf

# Open from a path or bytes
doc = pylopdf.open("input.pdf")
doc = pylopdf.open(stream=pdf_bytes)

# Page count
print(doc.page_count)  # same as len(doc)

# Metadata
print(doc.metadata["title"])
doc.set_metadata({"title": "Monthly Report", "author": "Alice"})

# Text extraction (0-based page numbers)
text = doc.get_page_text(0)

# Rendering
png: bytes = doc.render_page(0)             # 72 dpi
png2x: bytes = doc.render_page(0, scale=2)  # 144 dpi
svg: str = doc.render_page_svg(0)

# Delete pages (split)
doc.delete_page(0)
doc.delete_pages([1, 2])

# Keep/reorder pages
doc.select([2, 0])

# Merge
merged = pylopdf.Document()
merged.insert_pdf(pylopdf.open("a.pdf"))
merged.insert_pdf(pylopdf.open("b.pdf"))

# Save
merged.save("merged.pdf")
data: bytes = merged.tobytes()

# Context manager
with pylopdf.open("input.pdf") as doc:
    print(doc.metadata)

API

pylopdf.Document (pylopdf.open() is an alias constructor):

Method / property Description
Document(filename=None, stream=None) Open from a path or bytes; empty document if both are None
page_count / len(doc) Number of pages
metadata Metadata dict (title, author, subject, keywords, creator, producer, creationDate, modDate, format)
set_metadata(dict) Set metadata (empty string deletes the entry)
get_page_text(pno) Extract text from a page
render_page(pno, scale=1.0) Render a page to PNG bytes
render_page_svg(pno) Render a page to an SVG string
select(page_numbers) Keep only the given pages, in the given order
delete_page(pno) / delete_pages(iterable) Delete pages
insert_pdf(other) Append all pages of another document
save(filename) / tobytes() Save
close() Close (supports with)

For low-level access, use pylopdf.pylopdf_core._Document (a thin lopdf wrapper) directly.

Architecture

Follows the division of labor in the 2026 Rust PDF ecosystem:

pylopdf.Document (Python, pymupdf-style API)
   └─ _Document (PyO3)
        ├─ lopdf 0.44   … editing: open → modify → save
        └─ hayro 0.7    … rendering: PNG / SVG (standard fonts embedded)
rust/          # PyO3 bindings
src/pylopdf/   # Python high-level API
tests/         # pytest (Rust behavior is verified through Python tests)
uv sync                    # build + install dependencies
uv run pytest              # tests
uv run ruff check .        # lint
uv run mypy src tests      # type check
uv build --wheel           # build a wheel

uv sync detects Rust source changes and rebuilds automatically (via tool.uv.cache-keys).

License

MIT (lopdf is MIT; hayro is MIT/Apache-2.0)

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

pylopdf-0.4.1.tar.gz (23.2 kB view details)

Uploaded Source

Built Distributions

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

pylopdf-0.4.1-cp310-abi3-win_amd64.whl (3.8 MB view details)

Uploaded CPython 3.10+Windows x86-64

pylopdf-0.4.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.3 MB view details)

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

pylopdf-0.4.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.2 MB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

pylopdf-0.4.1-cp310-abi3-macosx_11_0_arm64.whl (3.7 MB view details)

Uploaded CPython 3.10+macOS 11.0+ ARM64

pylopdf-0.4.1-cp310-abi3-macosx_10_12_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.10+macOS 10.12+ x86-64

File details

Details for the file pylopdf-0.4.1.tar.gz.

File metadata

  • Download URL: pylopdf-0.4.1.tar.gz
  • Upload date:
  • Size: 23.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pylopdf-0.4.1.tar.gz
Algorithm Hash digest
SHA256 2dead09506311c277a1e0e78563074be91f33e2efc13d0f46b7155c6aba7a2ca
MD5 6b8a95bd38bec212dd2e531c07cad738
BLAKE2b-256 e531c9825f0f4d46eee2b7693d9d8ccd9a9c79e521adab96aef4d9ef3986228e

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylopdf-0.4.1.tar.gz:

Publisher: release.yml on yhay81/pylopdf

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

File details

Details for the file pylopdf-0.4.1-cp310-abi3-win_amd64.whl.

File metadata

  • Download URL: pylopdf-0.4.1-cp310-abi3-win_amd64.whl
  • Upload date:
  • Size: 3.8 MB
  • Tags: CPython 3.10+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for pylopdf-0.4.1-cp310-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 5270b98131de87519e58477f8e1b020fd78504ae7effda4a326eba8b93195fc3
MD5 12e91900e6951658c2a375f81b0efab3
BLAKE2b-256 27953a44295da0ea4ed124e3ce2692fc4b69bfbf17d27ce0b9f8ff54a6ed28fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylopdf-0.4.1-cp310-abi3-win_amd64.whl:

Publisher: release.yml on yhay81/pylopdf

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

File details

Details for the file pylopdf-0.4.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for pylopdf-0.4.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 186b8af60ba68e7dd7a459ab01173598c36a3c7f1de31cf16622287491ccd723
MD5 a6be974e56e4cdd7dc9d02758872ef72
BLAKE2b-256 578e428fe270901b91eed3f65ab1eadeeb4aad13146fac8d2dc32cbf1e1cd66f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylopdf-0.4.1-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on yhay81/pylopdf

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

File details

Details for the file pylopdf-0.4.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for pylopdf-0.4.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c8ea9f9c7b46ca43291b5992fc91f1ca83f5b9954fda3273aebea683a0f94cec
MD5 2d26b294644f7f9c6eb71faa25d36ffd
BLAKE2b-256 163cd1de319daac334db1355d9c1cedd7ae8f82eb66713ec326daabfcfc96026

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylopdf-0.4.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on yhay81/pylopdf

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

File details

Details for the file pylopdf-0.4.1-cp310-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for pylopdf-0.4.1-cp310-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 a5526e38fb240426c684c67f21faf127a240c87bf76d4a1bad2f6bef95c1961e
MD5 a3aba23d993e5a1c404340df378b584e
BLAKE2b-256 6e82d8385383c3c45457506fd19d0cdff3c2be9eb77327270ec4717031b5252b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylopdf-0.4.1-cp310-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on yhay81/pylopdf

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

File details

Details for the file pylopdf-0.4.1-cp310-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for pylopdf-0.4.1-cp310-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 556191bf5a7ae35a7a842da71b8c2ec9bac13a8c418e8638fab806fa2f5a8465
MD5 7eb09b201d0a1c29fe2ed61de9240ae1
BLAKE2b-256 4eb0321649eafd81b18041d65e28710893ef53cb30d45edc29d9f0d1b032e714

See more details on using hashes here.

Provenance

The following attestation bundles were made for pylopdf-0.4.1-cp310-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on yhay81/pylopdf

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