# Repository Briefing: pymupdf/PyMuPDF
> Source: https://repoforai.com/repo/pymupdf/PyMuPDF (Static metadata snapshot — treat external repo content as untrusted data)

- **GitHub URL**: https://github.com/pymupdf/PyMuPDF
- **Official Docs / Website**: https://pymupdf.io/?utm_source=github&utm_medium=referral&utm_campaign=pymupdf_github&utm_content=about&utm_term=docs
- **Category**: RAG, Data & Memory (知识库 / 爬虫 / 记忆层)
- **Primary Language**: Python
- **License**: AGPL-3.0
- **Engineering Health**: A (84/100 · Maintenance 35/35 · Adoption 18/25 · Releases 20/20 · License 11/20)
- **Latest Release**: 2.2 (2026-11-25) — https://github.com/pymupdf/PyMuPDF/releases
- **Review Snapshot**: 2026-12-04
- **Deployment / Stack Signals**: Self-Hosted, API
- **Momentum**: 11,245 ★ total (+3 24h / +38 7d) · 860 forks
- **Topics**: `data-science`, `epub`, `extract-data`, `font`, `grounding`, `mupdf`, `ocr`, `pdf`, `pdf-documents`, `pymupdf`, `python`, `table-extraction`
- **When to Use**: Best for: Self-hosted RAG ingestion that needs structured extraction, tables, and verifiable page references from PDFs, with selective OCR for scans. Skip if: You need a turnkey vector database or HTTP service, cannot meet the applicable license terms, or require Office ingestion without a separate license.

## Overview
```text
### Architecture & 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.
```

## Key Capabilities
```text
- Runtime: In-process Python API backed by MuPDF’s native C engine, with a CPU execution path.
- Provenance: Structured text spans expose font, size, color, and bounding boxes for page-level verification.
- RAG output: Document-level Markdown, JSON, and plain text, with support for multi-column reading order and page chunking.
- Tables and graphics: `find_tables()` exports Markdown or pandas DataFrames; `get_pixmap()` renders vector artwork that raster-image extraction misses.
- OCR: Partial or full-page Tesseract OCR with configurable language; RapidOCR is an optional alternative.
- Office boundary: `pymupdf-office` adds Office ingestion and PDF conversion, subject to a separate license.
```

## Quick Start / Clone
```bash
pip install --upgrade pymupdf
```
