diff-match-patch
Repackaging of Google's Diff Match and Patch libraries.
What it is and what it does
diff-match-patch is a Python port of Google's Diff Match and Patch library, originally built in 2006 to power Google Docs. It implements three core text-processing operations: diff (comparing two blocks of text and returning a list of differences), match (finding the best fuzzy match for a search string within a block of text), and patch (applying patches to text with best-effort recovery when the underlying text doesn't match exactly).
The library uses Myers' diff algorithm at its core, surrounded by pre-diff speedups and post-diff cleanups to improve both performance and output quality. It also implements a Bitap matching algorithm for flexible matching and patching. With no runtime dependencies and support for Python 3.7 or newer, it's straightforward to integrate into projects that need text synchronization, version control operations, or document comparison functionality.
Use it for:
- Generate unified diff output between two text documents for version control or change tracking systems
- Find the best fuzzy match for a search string within a large block of text, weighted for accuracy and location
- Apply patches to text with graceful degradation when the exact context doesn't match
- Build document collaboration features that need to track and apply text changes
- Implement text-based merge or conflict resolution in plain-text workflows
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides diff, match, and patch algorithms for comparing plain text, finding fuzzy matches, and applying patches—originally built for Google Docs and now maintained as a Python port of Google's Diff Match and Patch library.
Yes. The package is mature (first release 2011), has no security vulnerabilities, zero dependencies, and permissive licensing. Dormant maintenance is a minor concern, but the repository is active and tracks a maintained fork. Install it if you need robust diff, match, or patch operations for plain text—it's a well-established tool with low friction and proven algorithms.
Install
diff-match-patch on PyPI
pip
pip install diff-match-patchuv
uv add diff-match-patchpoetry
poetry add diff-match-patchInstalling diff-match-patch
Before you install
Low friction: pure Python wheel with no runtime dependencies and support for Python 3.7 or newer. Dormant maintenance status (last release October 2024, 662 days ago) but repository is not archived and tracks a maintained fork as of August 2024.
License in practice
Permissive Apache license allows commercial and private use without restriction, making it suitable for most projects without licensing concerns.
Quickstart
from diff_match_patch import diff_match_patch
dmp = diff_match_patch()
patches = dmp.patch_make(text1, text2)
diff = dmp.patch_toText(patches)
patches = dmp.patch_fromText(diff)
new_text, _ = dmp.patch_apply(patches, text)
Verify before relying
- Whether the maintained fork referenced (as of August 2024) is actively developed or if this package itself receives updates independently
- Performance characteristics and scalability limits for large text comparisons or patch operations
Package facts
| License | not declared (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 662 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 4,799,032/month — #2,227 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: diff_match_patch-20241021-py3-none-any.whl
Tags
More Libraries packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
python-dateutilProvides parsing, arithmetic, and recurrence…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
fast-diff-match-patchWraps the C++ implementation of…
permissive · top 15,000 on PyPI
patchParses and applies unified diff patches to…
permissive · top 15,000 on PyPI
dictdifferDictdiffer computes and applies diffs and…
permissive · top 5,000 on PyPI
whatthepatchParses and applies patch files in multiple diff…
permissive · top 5,000 on PyPI
patch-ngParses and applies unified diff patches to…
permissive · top 5,000 on PyPI
daffCompares two tables and produces a diff summary…
permissive · top 1,000 on PyPI
unidiff2Parses unified diff format into structured…
permissive · top 15,000 on PyPI
xmldiffxmldiff compares two XML files or trees and…
permissive · top 15,000 on PyPI
moreorlessGenerates unified diffs with correct handling…
permissive · top 5,000 on PyPI
fastdiffFastdiff provides a fast diff algorithm…
permissive · top 15,000 on PyPI