Python diff libraries

Updated Nov 2026

Python diff libraries compare two strings, documents, or data structures and describe what changed between them. A structural diff reports each change by its path inside nested data rather than as inserted and deleted characters. These libraries let apps and AI agents show what changed between two versions of a record or document.

Popularity

JSON Patch has the most monthly downloads among the dedicated diff libraries in this comparison, at 137.3M.

LibraryMonthly downloadsStarsLast releaseLicense
RapidFuzz
143.8M
4.2KAug 2026MIT
JSON Patch
137.3M
500Nov 2026BSD-3-Clause
DeepDiff
62.8M
2.5KNov 2026MIT
Levenshtein
20.5M
401Sep 2026GPL-2.0-or-later
jsondiff
7.1M
751Aug 2024MIT
Diff Match Patch
6.8M
59Oct 2024Apache-2.0
dictdiffer
5.8M
849Jul 2026MIT
xmldiff
345.8K
231Jun 2026MIT
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Matches strings with fast fuzzy comparison.

Downloads / mo
143.8M
Stars
4.2K
Last release
3.14.6
License
MIT

Quickstart

From Levenshtein.html
$ pip install rapidfuzz
from rapidfuzz.distance import Levenshtein

print(Levenshtein.editops("spam", "park"))

RapidFuzz examples

From open-source projects on GitHub

Creates and applies JSON Patch operation sequences between JSON documents.

Downloads / mo
137.3M
Stars
500
Last release
1.47
License
BSD-3-Clause

Strengths

  • Creates patches from document differences. Use make_patch to turn a source document into its destination.
  • Can check values before replacement. Enable generate_test_ops to detect changed values before applying a patch.

Limitations

  • Patch paths depend on source. Apply generated operations to the source document they were created from.
  • In-place operations change the input. Keep the default copy when the original document must remain unchanged.

Quickstart

From tutorial.rst
$ pip install jsonpatch
import jsonpatch

source = {"name": "old"}
patch = jsonpatch.make_patch(source, {"name": "new"})
print(patch.patch)

JSON Patch examples

From open-source projects on GitHub

Finds deep differences between Python objects and can create structured-data deltas.

Downloads / mo
62.8M
Stars
2.5K
Last release
9.2.1
License
MIT

Strengths

  • Compares nested Python objects. Report changes inside dictionaries, lists, and custom objects.
  • Can ignore iterable ordering. Use ignore_order when list position should not determine matching.

Limitations

  • Ignoring order hides duplicate changes. Enable report_repetition when repeated-item counts must be compared.
  • Custom objects need JSON mappings. Provide a conversion mapping for types the serializer cannot encode.

Quickstart

From basics.html
$ pip install deepdiff
from deepdiff import DeepDiff

print(DeepDiff({"name": "old"}, {"name": "new"}))

Computes string edit distances and similarities in a Python extension.

Downloads / mo
20.5M
Stars
401
Last release
0.27.5
License
GPL-2.0-or-later

Quickstart

From levenshtein.html
$ pip install Levenshtein
from Levenshtein import editops

print(editops("spam", "park"))

Levenshtein examples

From open-source projects on GitHub

Diffs JSON and JSON-like structures in Python.

Downloads / mo
7.1M
Stars
751
Last release
2.2.1
License
MIT

Quickstart

From __init__.py
$ pip install jsondiff
import jsondiff

print(jsondiff.diff({"name": "old"}, {"name": "new"}))

jsondiff examples

From open-source projects on GitHub

Diff Match Patch

Repackages the Google Diff Match and Patch libraries.

Downloads / mo
6.8M
Stars
59
Last release
20241021
License
Apache-2.0

Quickstart

From diff_match_patch.py
$ pip install diff-match-patch
from diff_match_patch import diff_match_patch

dmp = diff_match_patch()
print(dmp.diff_main("spam", "park"))

Diff Match Patch examples

From open-source projects on GitHub

Compares dictionary, list, and set structures and applies their change operations.

Downloads / mo
5.8M
Stars
849
Last release
0.10.0
License
MIT

Strengths

  • Diffs and patches dictionary structures. Apply returned change operations with patch or reverse them with revert.
  • Supports numeric comparison tolerance. Treat close numeric values as equal using a tolerance.

Limitations

  • Patching copies the destination. Set in_place to modify the original destination instead.

Quickstart

From index.rst
$ pip install dictdiffer
from dictdiffer import diff

print(list(diff({"name": "old"}, {"name": "new"})))

dictdiffer examples

From open-source projects on GitHub

Creates diffs of XML files.

Downloads / mo
345.8K
Stars
231
Last release
3.0
License
MIT

Quickstart

From api.html
$ pip install xmldiff
from xmldiff import main

print(main.diff_texts("<root/>", "<root><item/></root>"))

xmldiff examples

From open-source projects on GitHub

FAQ

DeepDiff suits nested Python objects and JSON-like data. JSON Patch suits changes that other systems must apply as standard JSON Patch operations. Diff Match Patch suits plain text with patches that tolerate shifted context.

DeepDiff finds deep differences between Python objects and reports them by path. Its Delta interface stores those changes and replays them against the original data.

The built-in difflib module compares two sequences of lines or characters. Diff Match Patch adds patch objects that apply to text with surrounding context, and Levenshtein computes edit distances and edit operations.

xmldiff compares parsed XML trees and returns semantic edit actions. Those actions apply to the original XML as a patch script.

For coding agents

Found your diff library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official