Edit, render, extract, and create PDFs in Python.
pylopdf follows the API of pymupdf, so code and knowledge carry over, but it is built on a Rust core and released under the MIT license. It installs as a single wheel with no required Python dependencies.
Documentation · Getting started · API reference · Migrating from pymupdf
Status: pylopdf is pre-1.0 and covers part of pymupdf's API so far. Breaking changes can still happen; the stability policy explains what may change.
pip install pylopdfPython 3.11 or newer. Wheels are available for Linux, macOS, and Windows, including free-threaded Python 3.14t and 3.15t.
Optional extras add fonts and OCR models:
| Extra | Adds |
|---|---|
jp, ko, zh-cn, zh-tw |
Japanese, Korean, and Chinese fonts for displaying and writing text |
ar, he, hi, th |
Arabic, Hebrew, Hindi, and Thai fonts for writing text |
ocr |
An offline OCR engine for scanned pages |
pip install "pylopdf[jp,ocr]"import pylopdf
doc = pylopdf.open("input.pdf")
page = doc[0]
# Extract
text = page.get_text() # plain text
words = page.get_text("words") # words with their positions
hits = page.search_for("invoice") # rectangles of each match
tables = page.find_tables()
markdown = doc.to_markdown() # whole document as Markdown
# Render
page.get_pixmap(dpi=150).save("page.png")
svg = page.get_svg_image()
# Add content
page.insert_text((72, 72), "Approved", fontsize=20, color=(0.8, 0, 0))
page.insert_image((72, 100, 200, 200), filename="logo.png")
page.add_highlight_annot(hits)
# Reorganize pages (fetch pages again with doc[i] afterwards)
doc.delete_pages([1, 2])
doc.insert_pdf(pylopdf.open("appendix.pdf")) # append another document
# Save
doc.save("output.pdf", garbage=True, deflate=True)The getting started guide covers each area in more detail.
- Pages and documents: merge, split, reorder, rotate, and delete pages; table of contents, page labels, metadata, and file attachments
- Text extraction: plain or positioned text, search, tables, Markdown output, and vertical Japanese/Chinese text
- Rendering: pages to PNG or SVG, with parallel rendering of many pages
- Adding content: text in any font with proper shaping, images, vector drawings, pages from other PDFs, highlights, and links
- Forms: fill in form fields
- OCR: make scanned pages searchable without installing Tesseract
- Saving: compression, cleanup of unused objects, and AES-256 encryption
- MIT licensed. pymupdf is AGPL or commercial.
- Small and self-contained. About 7 MB per wheel, with nothing else to install, so it fits AWS Lambda and similar environments. It also runs in WebAssembly, including Cloudflare Python Workers.
- Safe with untrusted files. Size and complexity limits raise a clear
LimitErrorinstead of exhausting memory;DocumentLimits.web()enables all of them. See the security model. - Built for concurrency. Heavy operations release the GIL, and free-threaded Python is supported. See the concurrency guide.
Redaction, editing or deleting annotations, creating form fields, and incremental saving are planned; the roadmap lists when.
Typesetting, PDF/A output, and digital signatures are out of scope. The ecosystem guide shows how to pair pylopdf with typst and pyHanko for those.
Benchmarks against pymupdf are reproducible from this repository, and the results include the cases where pylopdf is slower. See the benchmark page.
Bug reports and pull requests are welcome. Building from source needs a Rust toolchain and uv:
uv sync
uv run pytestCONTRIBUTING.md has the full development guide. Please report security issues privately through GitHub Security Advisories.
MIT. pylopdf is built on lopdf, hayro, krilla, and HarfRust; see NOTICE.md for third-party licenses.