skillfed

diff-match-patch

Repackaging of Google's Diff Match and Patch libraries.

diff-match-patch v20241021 4.8M downloads/30d#2,227 on PyPI59
Permissive license DORMANT released

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-patch

uv

uv add diff-match-patch

poetry

poetry add diff-match-patch

Installing 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

Development Status :: 6 - MatureIntended Audience :: DevelopersLicense :: OSI Approved :: Apache Software LicenseTopic :: Software Development :: LibrariesTopic :: Text Processing

Tags

text diff algorithmfuzzy text matchingpatch generation and applicationunified diff librarytext synchronizationplain text comparisonpatch file handling
text-diffversion-controltext-synchronization

More Libraries packages