{"id":23705,"library":"fast-diff-match-patch","title":"fast_diff_match_patch","description":"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.","status":"active","version":"2.1.0","language":"python","source_language":"en","source_url":"https://github.com/JoshData/fast_diff_match_patch","tags":["diff","match","patch","c++","string-diff","google-diff-match-patch"],"install":[{"cmd":"pip install fast-diff-match-patch","lang":"bash","label":"Installs the C++ implementation"}],"dependencies":[],"imports":[{"note":"Version 2.x removed the diff_match_patch class; use standalone functions: diff, match_main, patch_apply","wrong":"from fast_diff_match_patch import diff_match_patch","symbol":"diff","correct":"from fast_diff_match_patch import diff"},{"note":"","wrong":"","symbol":"match_main","correct":"from fast_diff_match_patch import match_main"},{"note":"","wrong":"","symbol":"patch_apply","correct":"from fast_diff_match_patch import patch_apply"}],"quickstart":{"code":"from fast_diff_match_patch import diff, match_main, patch_apply\n\n# Diff two strings\ntext1 = \"The quick brown fox\"\ntext2 = \"The quick blue fox\"\ndiffs = diff(text1, text2)\nprint(diffs)\n\n# Match a pattern in text\nmatch_result = match_main(text1, \"quick\", 0)\nprint(match_result)\n\n# Apply patches from a diff text\npatches = patch_apply(diff(text1, text2), text1)\nprint(patches)","lang":"python","description":"Demonstrates the three main functions: diff, match_main, patch_apply. Note that the API changed from the class-based interface in version 1.x."},"warnings":[{"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(...)`.","message":"Version 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.","severity":"breaking","affected_versions":"<2.0"},{"fix":"Run `pip install --upgrade fast-diff-match-patch` and update imports as above.","message":"Version 1.x is deprecated and no longer maintained. Upgrade to 2.x for the faster C++ backend.","severity":"deprecated","affected_versions":"1.x"},{"fix":"Use integer comparison: if op == -1: # delete; elif op == 0: # equal; elif op == 1: # insert.","message":"The 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.","severity":"gotcha","affected_versions":">=2.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Change import to `from fast_diff_match_patch import diff` and use `diff(text1, text2)` instead of `dmp.diff_main(text1, text2)`.","cause":"Version 2.x removed the class-based API. The library now provides standalone functions (diff, match_main, patch_apply).","error":"ImportError: cannot import name 'diff_match_patch' from 'fast_diff_match_patch'"},{"fix":"Use the correct import: `from fast_diff_match_patch import diff` and call `diff(...)`.","cause":"Calling `fast_diff_match_patch.diff(...)` without importing the function directly, or mistaking the module for a class.","error":"TypeError: 'module' object is not callable"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}