patch
Library to parse and apply unified diffs
What it is and what it does
Patch is a lightweight library and command-line tool that reads unified diff files and applies them to source code. It handles common diff problems automatically—correcting line endings to match the target file, fixing diffs broken by trailing whitespace stripping, and normalizing a/ and b/ path prefixes. It detects patch format from SVN, HG, or GIT sources and produces a diffstat histogram of changes applied.
The package is self-contained: a single Python file with no external dependencies beyond the standard library, designed to be copied into a repository or run directly as a zip archive. It works across Linux, Windows, and OS X. However, it does not support file renaming, creation, removal, directory tree operations, or version control–specific properties; it also cannot parse non-unified diff formats.
Use it for:
- Apply code patches in build systems or deployment scripts without requiring external utilities.
- Parse and validate unified diffs programmatically within Python tools or CI/CD pipelines.
- Correct malformed patches by automatically fixing whitespace and linefeed issues before application.
- Embed patch application logic in a single-file distribution without adding external dependencies.
- Generate and display diffstat summaries for patch review or logging.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parses and applies unified diff patches to files, with automatic correction of linefeeds, whitespace issues, and diff format variations across SVN, HG, and GIT.
No. The package is abandoned (last release 2016-02-13, no active maintenance) and poses compatibility and support risk. While its zero-dependency design and permissive license are attractive, the stalled development means unaddressed bugs and uncertain Python 3 compatibility. For new projects, seek actively maintained alternatives; for legacy code already depending on it, pin the version strictly and test thoroughly.
Install
patch on PyPI
pip
pip install patchuv
uv add patchpoetry
poetry add patchInstalling patch
Before you install
High install friction: the package is abandoned (last release 2016-02-13, last commit 2022-01-25) with no active maintenance. The single-file design and zero runtime dependencies mean installation itself is straightforward, but the stalled development poses risk for unaddressed bugs.
License in practice
MIT License permits free use, modification, and distribution with minimal restrictions, making it suitable for both open-source and commercial projects provided the license notice is retained.
Quickstart
pip install "patch==1.*"
import patch
patch.fromfile('diff.patch')
No external dependencies, but package is abandoned since 2016-02-13 with no active maintenance.
Verify before relying
- Whether the package remains compatible with current Python 3 versions beyond those tested at release.
- Whether file renaming, creation, removal, and directory operations are genuinely unsupported or simply untested.
- Current real-world usage patterns and whether the 620187 monthly downloads reflect active use or legacy dependents.
Package facts
| License | MIT License (permissive) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | abandoned — 3,835 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 620,187/month — #5,726 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: patch-1.16.zip
Tags
More Build Tools packages
Provides reusable utilities for Python…
permissive · top 100 on PyPI
tqdmWraps any iterable to display a real-time…
copyleft · top 100 on PyPI
pippip is the standard installer for Python…
permissive · top 100 on PyPI
hatchlingHatchling is a standards-compliant Python build…
permissive · top 100 on PyPI
grpcio-toolsGenerates Python gRPC service stubs and message…
permissive · top 1,000 on PyPI
pre-commitpre-commit is a framework for installing and…
permissive · top 1,000 on PyPI
bsdiff4bsdiff4 creates and applies binary patches in…
permissive · top 15,000 on PyPI
moreorlessGenerates unified diffs with correct handling…
permissive · top 5,000 on PyPI
patch-ngParses and applies unified diff patches to…
permissive · top 5,000 on PyPI
patchyPatchy modifies Python functions at runtime by…
permissive · top 5,000 on PyPI
whatthepatchParses and applies patch files in multiple diff…
permissive · top 5,000 on PyPI
diff-match-patchProvides diff, match, and patch algorithms for…
permissive · top 5,000 on PyPI
unidiff2Parses unified diff format into structured…
permissive · top 15,000 on PyPI
unidiffParses unified diff format data into structured…
permissive · top 1,000 on PyPI
xmldiffxmldiff compares two XML files or trees and…
permissive · top 15,000 on PyPI
fast-diff-match-patchWraps the C++ implementation of…
permissive · top 15,000 on PyPI