pypdf

A pure-Python library for splitting, merging, cropping, transforming, and extracting content from PDF files.

Library
PyPI
v6.21.2
10,269 stars
BSD 3-Clause License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
95 /100 Excellent
Development Activity 100
Maintenance 96
Community 84
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
86 /100 Excellent
Architecture 85
Code Quality 92
Innovation 78
Learning Curve 90

pypdf is a free, open-source, pure-Python library for working with PDF files. It can split, merge, crop, and transform pages, add passwords and viewing restrictions, extract text and metadata, and manipulate annotations, bookmarks, and form fields — all without any external binary dependencies like Poppler or MuPDF.

The library grew out of the original PyPDF2 project and has since become the de facto standard pure-Python PDF toolkit, with over 27 million weekly downloads on PyPI. It ships full type hints (mypy strict mode) and a test suite exercising real-world PDF files pulled from a companion sample-files repository, which has made it a dependency of choice for teams that need predictable, dependency-light PDF processing inside Python backends, data pipelines, and document-automation tools.

What You Get

  • PdfReader and PdfWriter classes for loading, creating, and saving PDF documents from files, bytes, or streams
  • Page-level operations: merge, split, rotate, crop, scale, and overlay/watermark pages via the Transformation API
  • Text and metadata extraction, including layout-aware extraction modes for tables and multi-column documents
  • Encryption and decryption support (standard and AES, with cryptography or PyCryptodome as optional backends)
  • Direct access to the low-level PDF object model (generic module) for advanced manipulation of dictionaries, streams, and cross-reference tables
  • Form field (AcroForm) reading and filling, annotation manipulation, and outline/bookmark management
  • Full static typing (py.typed, mypy strict) so downstream code gets accurate autocomplete and type checking

Common Use Cases

  • Merging or splitting multi-page PDF reports generated by other systems
  • Stripping or adding passwords and permissions to PDFs before distribution
  • Extracting text and structured metadata from PDFs for search indexing or document pipelines
  • Watermarking or stamping generated PDFs (e.g. invoices, contracts) with overlay pages
  • Filling and reading AcroForm fields in PDF-based forms as part of document-automation workflows

Under The Hood

Architecture

pypdf splits into a high-level document API (PdfReader and PdfWriter, sharing common logic through a PdfDocCommon mixin) and a low-level PDF object model (dictionaries, arrays, streams, indirect references, cross-reference tables) that both classes operate on directly. Page-level logic (PageObject, Transformation) composes onto that object model rather than duplicating parsing, and stream filtering/decoding (compression, image formats) is isolated from encryption, which is fully separated with pluggable crypto backends. This layered design means most feature work touches the page or object-model layer without needing to change the reader/writer’s core parsing, though the object model is foundational enough that a breaking change there would ripple through nearly every module.

Tech Stack

Pure Python 3.9+ with no mandatory runtime dependencies beyond a typing backport on older interpreters; optional extras (cryptography or PyCryptodome for AES, Pillow for image extraction, fonttools, arabic-reshaper/python-bidi for right-to-left text) are declared as pip extras so consumers only install what they use. The build backend is flit_core with packaging metadata centralized in pyproject.toml, and documentation is built with Sphinx and hosted on Read the Docs.

Code Quality

The test suite is extensive and runs with network access disabled by default, with tests opting into network or “real-world sample” access via explicit markers backed by a companion sample-files repository. CI runs the suite across multiple operating systems and Python versions (including PyPy) with parallelized test execution and coverage upload, plus a dedicated strict-mode type-check pass. Linting is configured to select the full rule set of its linter with an explicit, reasoned set of exceptions rather than a loose default configuration. Combined with full static typing throughout the package, this is a rigorously tooled codebase relative to typical pure-language libraries in its category.

API Design The public surface is deliberately small — only a handful of top-level classes and helpers are exported, keeping a much larger implementation mostly hidden behind two entry points. Getting started requires almost no boilerplate: loading a file and extracting text from its first page is a one-liner. The reader and writer share behavior through a common mixin so both feel consistent, and advanced users can drop into the low-level object model when the high-level API doesn’t cover a case, though that layer demands more familiarity with the PDF specification itself. Errors are raised as a typed hierarchy rather than generic exceptions, which aids programmatic handling upstream.

Used by 24 apps in this directory

Python
53%
AGPL 3.0

LearnHouse

CMS · Learning Management

2,413

Open-source LMS with AI tutoring, real-time collaboration boards, live code execution, and built-in course monetization — self-hosted in minutes.

View details
90
Repo Health
77
Technical
65
Dependency
Built with
Python 53%
TypeScript 45%
Updated 6 days ago
Python
84%
MIT

LiteLLM

AI Development · Developer Tools

61,933

Open source AI gateway and Python SDK that gives you one OpenAI-compatible interface to call 100+ LLM providers, with built-in routing, cost tracking, guardrails, and virtual keys.

View details
93
Repo Health
81
Technical
69
Dependency
Built with
Python 84%
TypeScript 11%
Updated 6 days ago
Rust
84%
Apache 2.0

liteparse

Developer Tools

12,906

A fast, lightweight, open-source document parser that extracts spatial text, bounding boxes, and Markdown from PDFs and Office files — entirely on your machine.

View details
83
Repo Health
80
Technical
71
Dependency
Built with
Rust 84%
Updated 1 weeks ago
Python
45%
GPL 3.0

MaxKB

AI Development · Knowledge Management

23,022

Build enterprise-grade AI agents with RAG, workflows & multi-modal support

View details
92
Repo Health
68
Technical
66
Dependency
Built with
Python 45%
Vue 37%
TypeScript 17%
Updated 1 weeks ago
Go
93%
MIT

NornicDB

AI Development · AI Memory · Databases

916

A single graph+vector+temporal database for AI workloads — Neo4j-compatible, sub-millisecond hybrid search, and built-in memory decay.

View details
80
Repo Health
82
Technical
71
Dependency
Built with
Go 93%
Updated 6 days ago
Python
38%
Other

Open WebUI

AI Agents · AI Assistants

156,607

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
92
Repo Health
75
Technical
66
Dependency
Built with
Python 38%
Svelte 35%
JavaScript 19%
Updated 6 days ago
TypeScript
92%
Other

OpenHands

AI Code Assistants · AI Development

91,695

The self-hosted developer control center for running AI coding agents — locally, in Docker, on VMs, or across cloud backends — with automation workflows for GitHub, Slack, and more.

View details
91
Repo Health
82
Technical
67
Dependency
Built with
TypeScript 92%
Updated 1 weeks ago
Python
62%
Apache 2.0

Polar

Developer Tools · Ecommerce · Invoicing Finance

10,410

Open source payments infrastructure that turns software into a business — subscriptions, usage-based billing, digital products, and merchant-of-record compliance in one platform.

View details
90
Repo Health
82
Technical
66
Dependency
Built with
Python 62%
TypeScript 31%
Updated 1 weeks ago
Python
55%
Other

PostHog

Ab Testing Experimentation · Analytics · Developer Tools

40,397

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
65
Dependency
Built with
Python 55%
TypeScript 36%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers