--- id: patch-ng version: "1.19.1" license: MIT license_treatment: permissive maintenance: active --- # patch-ng — Library to parse and apply unified diffs. License: permissive · Maintenance: active · Downloads: 4.7M/mo ## 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 above — verify before relying. Parses and applies unified diff patches to files, with automatic correction of linefeeds, whitespace issues, and diff prefixes. 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 pip install patch-ng uv add patch-ng poetry add patch-ng ## Installing patch-ng 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. 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() Requires Python 3.6 or later; file renaming, creation, removal, and directory operations are not supported. 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_current - Install friction: low - Maintenance: active - Downloads: 4.7M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags parse unified diffs, apply patch files, diff patching library, unified diff parser, patch file application, diff format handling, automatic patch correction, diff-patching, build-automation, no-dependencies [View on SkillFed](https://skillfed.io/packages/patch-ng) · [View on PyPI](https://pypi.org/project/patch-ng/)