patch-ng
Library to parse and apply unified diffs.
Decision gist · record as of 2026-08-14
Yes. The package is actively maintained, has no external dependencies, and solves a specific, well-defined problem—parsing and applying unified diffs with automatic correction of common issues. It is stable (Production/Stable status), widely used (top 5000 PyPI packages), carries no known vulnerabilities, and uses a permissive MIT license. Install it if you need to apply patches programmatically or embed patch logic without dependency overhead.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires Python 3.6 or later; file renaming, creation, removal, and directory operations are not supported.
- Low friction: pure Python with no external dependencies, distributed as a single wheel.
- Actively maintained with recent commits; last release 113 days ago.
License · maintenance · safety
MIT (permissive) — MIT license permits unrestricted use, modification, and distribution in commercial and private projects with minimal obligations.
last release 2026-04-23 (113 days) · last repo commit 2026-04-23 · 40 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 4,710,651 downloads/mo, #2,250 on PyPI
Alternatives
Verify before relying
pip install patch-ng
from patch_ng import PatchSet
with open('diff.patch') as f:
patches = PatchSet(f)
patches.apply()- Exact behavior when applying patches to files with mixed line endings or encoding issues.
- Performance characteristics on large patches or files.
- Whether the package handles edge cases in malformed diffs beyond the documented automatic corrections.
What it is and what it does
Patch NG is a maintained fork of the original python-patch library, designed to parse and apply unified diff patches to files. It operates as a self-contained Python module with no external dependencies, making it suitable for embedding directly in projects or installing via pip. The library automatically corrects common diff issues—linefeeds mismatched to the target file, diffs corrupted by whitespace stripping, and a/ and b/ prefixes—and detects patch format (SVN, HG, GIT). It runs on Python 3.6 and later across Linux, Windows, and macOS.
The fork was created to address stalled maintenance in the original project, accepting pull requests that had been pending review since mid-2019. It works as both a command-line tool and a library, offering a diffstat histogram for inspection. The package does not handle file renaming, creation, removal, directory tree operations, or version-control-specific metadata; it is limited to applying unified diff formats to existing files.
Use it for
- Automatically apply code patches or configuration diffs during build or deployment pipelines.
- Parse and inspect unified diffs programmatically to extract or validate patch metadata.
- Correct malformed patches by automatically fixing whitespace and linefeed inconsistencies.
- Embed patch application logic in tools without introducing external dependencies.
- Generate and display diffstat histograms for patch review or reporting.
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes.
The package is actively maintained, has no external dependencies, and solves a specific, well-defined problem—parsing and applying unified diffs with automatic correction of common issues. It is stable (Production/Stable status), widely used (top 5000 PyPI packages), carries no known vulnerabilities, and uses a permissive MIT license. Install it if you need to apply patches programmatically or embed patch logic without dependency overhead.
Install
patch-ng on PyPI
Before you install
Low friction: pure Python with no external dependencies, distributed as a single wheel. Actively maintained with recent commits; last release 113 days ago.
Requires Python 3.6 or later; file renaming, creation, removal, and directory operations are not supported.
License in practice
MIT license permits unrestricted use, modification, and distribution in commercial and private projects with minimal obligations.
Quickstart
pip install patch-ng
from patch_ng import PatchSet
with open('diff.patch') as f:
patches = PatchSet(f)
patches.apply()
Verify before relying
- Exact behavior when applying patches to files with mixed line endings or encoding issues.
- Performance characteristics on large patches or files.
- Whether the package handles edge cases in malformed diffs beyond the documented automatic corrections.
Package facts
| License | MIT permissive |
| Python support | Supports the current Python release >=3.6 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | None |
| Maintenance | Actively maintained 113 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 4,710,651 / month, #2,250 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Topic :: Software Development :: Build Tools |
Evidence: patch_ng-1.19.1-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “parse unified diffs”
- patch-ngParses and applies unified diff patches to files, with automatic…
- unidiffParses unified diff format data into structured Python objects,…
- unidiff2Parses unified diff format into structured Python objects…
Give your agent the search over MCP, or paste the wish link into any chat.
More Build Tools packages
Provides reusable utilities for Python packaging interoperability, including version handling, specifiers, markers, requirements, tags, and metadata parsing according to standards like PEP 440 and PEP 425.
Wraps any iterable to display a real-time progress bar in the terminal or Jupyter notebook, showing iteration count, elapsed time, and estimated time remaining.
pip is the standard installer for Python packages, enabling you to download and install packages from the Python Package Index and other indexes into your Python environment.
Hatchling is a standards-compliant Python build backend that handles packaging, metadata, and distribution of Python projects when configured in a project's pyproject.toml file.
Generates Python gRPC service stubs and message classes from Protocol Buffer definitions, enabling developers to build gRPC clients and servers.
pre-commit is a framework for installing and running git hooks written in any language before commits are made, automating code quality and validation checks across multi-language projects.
Install it if your team needs consistent, automated validation at commit time.
See also patch · moreorless · whatthepatch · patchy · diff-match-patch · unidiff · unidiff2 · fast-diff-match-patch · xmldiff · jsonpatch