pymupdf/PyMuPDF
MuPDF-backed Python engine for layout-aware document ingestion and page grounding
Automated SPDX check for reference only — not legal advice. Disclaimer
GitHub Star History
Full-history star trajectory from GitHub official history. Switch ranges or hover any point for exact counts.
Evidence-Backed Technical Brief
AI Deep ReviewArchitecture & Core Mechanics
PyMuPDF is an ingestion component for RAG, not a database or retrieval service. Its Python API calls the MuPDF C engine in-process: pymupdf.open() yields a document, and page objects expose text, tables, images, and rendering. page.get_text("dict") returns blocks, lines, and spans with geometry and styling. A pipeline can retain page identifiers and bounding boxes alongside chunks so a later citation can point back to the source.
The 2.x document-level API adds layout-aware Markdown, JSON, and plain text. Certain ML layout features use ONNX Runtime and can run on CPU. OCR is a separate path for image-only pages or broken text mappings. Office ingestion extends the same document interface through pymupdf-office, rather than requiring an Office application or LibreOffice subprocess. For packaging, pyproject.toml declares pipcl as a build requirement and a local setup backend; that build configuration is distinct from runtime dependencies such as ONNX Runtime for applicable layout features.
Key Capabilities & Differentiators
For PDFs, the core can extract text with position and style metadata, find tables and export them to Markdown or pandas, and render pages to a Pixmap at a chosen DPI. Embedded raster images can be extracted separately, but vector-only charts must be rendered to capture their appearance. The same library handles annotations, applied redactions, AcroForm fields, page reordering, merging, and splitting.
The input surface also includes XPS, EPUB, SVG, Markdown, and common raster formats. The licensed Office extension adds Word, Excel, PowerPoint, HWP, and HWPX inputs. Layout-aware output supports multi-column reading order and page chunking. On ExtractBench’s 370 PDFs, RapidOCR scored 85.20% overall versus Tesseract’s 78.31%, but Tesseract led 30.49% to 29.22% on the 20 documents over 50 pages. That reversal makes a corpus-specific OCR trial more useful than a blanket backend choice.
Trade-offs & Limitations
Compared with a pure-Python text extractor, PyMuPDF is a stronger fit when one pipeline needs page rendering, table extraction, edits, and source coordinates. If clean text is the only deliverable, a narrower parser may be easier to package on targets without compatible wheels. Local processing avoids a cloud OCR round trip and keeps source files inside the deployment boundary, but operators must provision OCR dependencies and absorb the CPU and memory cost of high-DPI rendering and concurrent scans.
Native extraction is not reliable for image-only PDFs or fonts without usable Unicode mappings, so budget for selective OCR and validate reading order and table boundaries on representative documents. Source-page metadata helps reviewers check an answer; it does not ensure that a retriever or LLM cites the right evidence. Assess AGPL-3.0 obligations against your distribution and network-service model, or evaluate commercial terms. The separate Office extension’s keyless evaluation is time-limited and exposes only the first three pages per document.
Hardware & Deployment Guide
Install with python -m pip install --upgrade pymupdf and use import pymupdf. The 2.x platform matrix lists Python 3.11–3.15 and wheels for supported Windows, macOS, manylinux, and musllinux targets; source installation needs a C/C++ toolchain. Run pymupdf-config to inspect the installation. Provision ONNX Runtime compatibility for layout features, Tesseract and language data or RapidOCR for scans, and a separately licensed Office extension if needed.
Self-hosting means embedding the Python API in your own process or worker, not deploying a bundled HTTP service. Stage the required packages and OCR assets ahead of time for an offline environment. Establish CPU, peak memory, and timeout budgets on a mixed batch of native PDFs, scans, and large pages before setting concurrency. Version 2.0 marks the layout-aware extraction milestone; the 2.1 and 2.2 release entries primarily list fixes. Pin and regression-test the version used for production ingestion.
find_tables() exports Markdown or pandas DataFrames; get_pixmap() renders vector artwork that raster-image extraction misses.pymupdf-office adds Office ingestion and PDF conversion, subject to a separate license.Self-hosted RAG ingestion that needs structured extraction, tables, and verifiable page references from PDFs, with selective OCR for scans.
You need a turnkey vector database or HTTP service, cannot meet the applicable license terms, or require Office ingestion without a separate license.
Quick Start & Installation
pip install --upgrade pymupdf
Comparison vs. Top RAG, Data & Memory Alternatives
Full comparison →| Repository | Stars | 7d Trend | Stack | License | Core Positioning |
|---|---|---|---|---|---|
| PyMuPDF ★ | 11.2k | +38 | Python | AGPL-3.0 | MuPDF-backed Python engine for layout-aware document ingestion and page groundin |
| MinerU | 84.7k | +326 | Python | — | Local document parser and library for structured RAG ingestion and page-level ci |
| marker | 41.2k | +103 | Python | Apache-2.0 | Hybrid OCR and layout parsing for document ingestion in RAG pipelines |
| markitdown | 199.7k | +909 | Python | MIT | Python library and CLI that turn mixed-format documents into Markdown for RAG in |
AI Context Briefing (for Claude / Cursor / Windsurf)
Standardized architecture summary & quickstart commands ready to paste into coding agents.
curl -sL https://repoforai.com/repo/pymupdf/PyMuPDF.md
Active README embeds unlock Hot-Tier 6h Telemetry Refresh automatically (zero pay-to-rank).
Frequently Asked Questions about PyMuPDF
How does PyMuPDF fit into a RAG ingestion service?
pymupdf.open(), use page.get_text("dict") for span coordinates or doc.to_markdown() for layout-aware text, and carry source document and page identifiers into your chunks. Embedding, indexing, retrieval, and any HTTP interface are separate components.Does it need a GPU, and how should I size workers?
Can a proprietary or air-gapped service use it?
When should I choose it over a simpler Python parser or an OCR-first service?
Upstream README & Documentation
This profile focuses on independent engineering analysis and live telemetry. Read the full upstream README, changelog, and examples directly on GitHub.
Top 10 Breakout Open-Source AI Repos, Every Thursday
Signal-only digest of fast-growing AI repos, SPDX license alerts, and architecture picks. Zero spam.
Zero spam · 1-click unsubscribe · Privacy Policy