Registry / serialization / fast-diff-match-patch

fast-diff-match-patch

JSON →
library2.1.0pypypi✓ verified 90d ago

Packages the C++ implementation of google-diff-match-patch for Python, providing fast byte and string diffs, match, and patch operations. Current version 2.1.0 is the C++ implementation, replacing an earlier pure Python version (1.x). Release cadence is low; version 2.0 introduced the C++ backend.

pip install fast-diff-match-patch
INSTALL
IMPORT
SIG · FAST-DIFF-MATCH-PA
F
fast-diff-match-patch
serializationpythonv2.1.0
Install
1.6s avg
Import
—
Disk
22MB
Pass rate
8/ 10
Env Coverage8 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v2.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✓ —
✓ 1.6s
py 3.11
✓ —
✓ 1.5s
py 3.12
✓ —
✓ 1.4s
py 3.13
✕ build_error
✕ build_error
py 3.9
✓ —
✓ 1.7s
22MB installed
● package 22MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

diff
✓ from fast_diff_match_patch import diff
✗ from fast_diff_match_patch import diff_match_patch
Version 2.x removed the diff_match_patch class; use standalone functions: diff, match_main, patch_apply
match_main
✓ from fast_diff_match_patch import match_main
patch_apply
✓ from fast_diff_match_patch import patch_apply

Demonstrates the three main functions: diff, match_main, patch_apply. Note that the API changed from the class-based interface in version 1.x.

from fast_diff_match_patch import diff, match_main, patch_apply # Diff two strings text1 = "The quick brown fox" text2 = "The quick blue fox" diffs = diff(text1, text2) print(diffs) # Match a pattern in text match_result = match_main(text1, "quick", 0) print(match_result) # Apply patches from a diff text patches = patch_apply(diff(text1, text2), text1) print(patches)
Debug
Known issues
breakingVersion 2.0+ replaced the pure-Python implementation with a C++ wrapper. The API changed from a class-based interface (diff_match_patch) to standalone functions (diff, match_main, patch_apply). Old code using diff_match_patch will break.
fix
Replace `from fast_diff_match_patch import diff_match_patch; dmp = diff_match_patch(); dmp.diff_main(...)` with `from fast_diff_match_patch import diff; diff(...)`.
affects: <2.0
deprecatedVersion 1.x is deprecated and no longer maintained. Upgrade to 2.x for the faster C++ backend.
fix
Run `pip install --upgrade fast-diff-match-patch` and update imports as above.
affects: 1.x
gotchaThe output of `diff` is a list of tuples `(operation, text)` where operation is `-1` (delete), `0` (equal), or `1` (insert). This differs from the original google-diff-match-patch library which sometimes uses enum-like constants.
fix
Use integer comparison: if op == -1: # delete; elif op == 0: # equal; elif op == 1: # insert.
affects: >=2.0
Errors
Common errors & fixes
ImportError: cannot import name 'diff_match_patch' from 'fast_diff_match_patch'
Version 2.x removed the class-based API. The library now provides standalone functions (diff, match_main, patch_apply).
fix
Change import to `from fast_diff_match_patch import diff` and use `diff(text1, text2)` instead of `dmp.diff_main(text1, text2)`.
TypeError: 'module' object is not callable
Calling `fast_diff_match_patch.diff(...)` without importing the function directly, or mistaking the module for a class.
fix
Use the correct import: `from fast_diff_match_patch import diff` and call `diff(...)`.
Upgrade
Version history
2.1.0latest on PyPI · released Apr 23, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
Resources
fast-diff-match-patch — pip install fast-diff-match-patch · libregistry