unidiff2
Unified diff parsing/metadata extraction library.
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 unidiff2uv
uv add unidiff2poetry
poetry add unidiff2Installing 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
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
unidiffParses unified diff format data into structured…
permissive · top 1,000 on PyPI
patchParses and applies unified diff patches to…
permissive · top 15,000 on PyPI
whatthepatchParses and applies patch files in multiple diff…
permissive · top 5,000 on PyPI
types-unidiffProvides type stubs for the unidiff package,…
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
diff-parserParses git diff and .diff files to extract…
permissive · top 15,000 on PyPI
diff-match-patchProvides diff, match, and patch algorithms for…
permissive · top 5,000 on PyPI
icdiffIcdiff displays file differences in a…
permissive · top 5,000 on PyPI
reqifReqIF is a Python library for parsing,…
permissive · top 15,000 on PyPI