ScriptsJul 20, 2026·3 min read

PyMuPDF — High-Performance PDF Processing for Python

PyMuPDF is a Python binding for the MuPDF library that provides fast, comprehensive PDF (and other document) processing. It supports text extraction, rendering, annotation, merging, form filling, and OCR across PDF, XPS, EPUB, and image formats.

Agent ready

Ready-to-run agent install

This asset can be installed after the agent chooses its runtime, checks the plan, and runs the matching command.

Native · 98/100Policy: allow
Agent surface
Any MCP/CLI agent
Kind
Skill
Install
Single
Trust
Trust: Established
Entrypoint
PyMuPDF
Direct install command
npx -y tokrepo@latest install c4de9c4b-8437-11f1-9bc6-00163e2b0d79 --target codex

Run after dry-run confirms the install plan.

Introduction

PyMuPDF (also known as fitz) is a Python library that wraps the MuPDF rendering engine from Artifex. It provides fast, low-level access to PDF documents for text extraction, page rendering, annotation manipulation, and structural analysis. PyMuPDF is widely used in data pipelines, document processing systems, and AI workflows that require reliable PDF parsing.

What PyMuPDF Does

  • Extracts text, images, tables, and metadata from PDF documents with positional data
  • Renders pages to images at configurable resolution for OCR or preview pipelines
  • Creates, modifies, and merges PDF files programmatically
  • Handles annotations, links, bookmarks, and form fields across documents
  • Supports PDF, XPS, EPUB, MOBI, FB2, CBZ, SVG, and common image formats

Architecture Overview

PyMuPDF provides Python bindings to MuPDF, a lightweight PDF and document renderer written in C. The library loads documents into memory-efficient structures and exposes page-level operations through a Pythonic API. Text extraction preserves layout information including coordinates, font details, and reading order. The rendering pipeline converts pages to pixmaps that can be exported as PNG, JPEG, or raw pixel buffers.

Self-Hosting & Configuration

  • Install with pip install pymupdf on Python 3.8 or later
  • No external system dependencies required; MuPDF is statically linked
  • Use pymupdf.open() to load documents from file paths, byte streams, or URLs
  • Configure text extraction mode with flags for blocks, words, or raw characters
  • Enable OCR integration by installing Tesseract and using page.get_textpage_ocr()

Key Features

  • Processes PDF pages in microseconds with one of the fastest Python PDF engines
  • Preserves spatial layout with bounding-box coordinates for every text span
  • Extracts embedded images in their original format without re-encoding
  • Supports incremental saves to minimize file rewrites on large documents
  • Provides table detection and extraction without external dependencies

Comparison with Similar Tools

  • pdfplumber — Higher-level API for tables but slower; PyMuPDF is faster for raw extraction
  • PyPDF2/pypdf — Pure Python with no rendering; PyMuPDF handles rendering and complex layouts
  • Tabula — Java-based table extractor; PyMuPDF stays within the Python ecosystem
  • pdfminer — Focused on text extraction; PyMuPDF also handles images, annotations, and rendering
  • Docling — AI-focused document parser; PyMuPDF provides lower-level control and faster throughput

FAQ

Q: What is the relationship between PyMuPDF and fitz? A: fitz is the historical import name (import fitz). Recent versions also support import pymupdf. Both refer to the same library.

Q: Can PyMuPDF handle password-protected PDFs? A: Yes. Pass the password as a parameter to pymupdf.open() to decrypt and process protected documents.

Q: Does PyMuPDF support OCR for scanned documents? A: Yes. With Tesseract installed, use page.get_textpage_ocr() to extract text from scanned or image-based pages.

Q: How does PyMuPDF compare in speed to other PDF libraries? A: PyMuPDF is consistently among the fastest Python PDF libraries due to its C-based MuPDF engine, often processing pages 5-10x faster than pure-Python alternatives.

Sources

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets