skillfed

unidiff2

Unified diff parsing/metadata extraction library.

unidiff2 v0.7.8 196.5K downloads/30d#9,784 on PyPI1
Permissive license MIT AGING released

What it is and what it does

unidiff2 is a Python library that parses unified diff format (the standard output of `git diff`, `patch` files, and similar tools) into a structured object model. It lets you programmatically inspect which files changed, how many lines were added or removed, access individual hunks and their line-by-line content, and regenerate diff output from the parsed structure.

The package is a maintained fork of the original unidiff library. It has no external runtime dependencies and supports Python 3.7 through 3.11. You can load diffs from files, file-like objects, or iterables, and optionally parse metadata-only for efficiency. It also provides a command-line tool to summarize diff statistics.

Use it for:

  • Analyze git diffs programmatically in CI/CD pipelines to enforce code review policies or generate reports
  • Parse patch files to determine which files and functions were modified without applying the patch
  • Build tooling that needs to understand the structure of code changes (e.g., impact analysis, test selection)
  • Extract and display diff statistics in a custom format or dashboard

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Parses unified diff format into structured Python objects representing patches, files, hunks, and line-by-line changes, with methods to query file status and rebuild diff output.

Yes, if you need to parse unified diffs in Python and want a dependency-free solution. The low install friction and permissive license are advantages. However, the package is very new (first release October 2025) and aging maintenance status means you should verify that it meets your stability expectations and that the original unidiff project hasn't resumed active development before committing to it in production.

Install

unidiff2 on PyPI

pip

pip install unidiff2

uv

uv add unidiff2

poetry

poetry add unidiff2

Installing unidiff2

Before you install

Low friction—pure Python wheel with no runtime dependencies. Maintenance status is aging: last commit was 2025-11-03 and the package is only a few months old (first release 2025-10-03), so long-term stability is unproven.

License in practice

MIT license is permissive; you can use, modify, and distribute this package with minimal restrictions, provided you retain the license notice.

Quickstart

pip install unidiff2

from unidiff import PatchSet
patch = PatchSet.from_filename('file.diff', encoding='utf-8')
for patched_file in patch:
    print(f"{patched_file.path}: +{patched_file.added} -{patched_file.removed}")

Verify before relying

  • Whether this fork is actively maintained long-term or if the original unidiff package has resumed development
  • Performance characteristics when parsing very large diff files
  • Compatibility with edge cases in diff formats from different tools (e.g., Mercurial, Bazaar, Subversion)

Package facts

License MIT (permissive)
Python support supports the current Python release (>=3.7)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance aging — 288 days since the last release
Last repo commit
First released
Downloads 196,523/month — #9,784 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: unidiff2-0.7.8-py3-none-any.whl

Keywords: unified, diff, parse, metadata

Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

parse unified diff formatdiff parsing libraryextract patch metadataread git diff programmaticallyunified diff parser
diff-parsingversion-control

More Software Development packages