skillfed

patch

Library to parse and apply unified diffs

patch v1.16 620.2K downloads/30d#5,726 on PyPI123
Permissive license MIT License Abandoned released

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 patch

uv

uv add patch

poetry

poetry add patch

Installing 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

Programming Language :: Python :: 2Programming Language :: Python :: 3

Tags

apply unified diff patchesparse patch filesdiff file patchingunified diff parserpatch application librarydiff format correctioncross-platform patching
diff-patchingabandoned

More Build Tools packages