gitmyhub

deepdiff

Python ★ 0 updated 7y ago ⑂ fork

Deep Difference and search of any Python object/data.

DeepDiff compares two Python objects of almost any type and reports exactly what changed, down to the precise nested path of each difference.

Pythonsetup: easycomplexity 2/5

DeepDiff is a Python tool that compares two objects of almost any type—dictionaries, lists, strings, custom classes, and more—to tell you exactly what changed between them. Instead of just saying "these are different," it drills down into nested structures and shows you the precise path to every change, whether items were added, removed, modified, or their type changed entirely.

Think of it like a very smart diff tool for your data. If you have two JSON-like objects and want to know what's different, you pass them both to DeepDiff and get back a detailed report. For example, you could compare two versions of a user database and see that root['user_42']['email'] changed from "[email protected]" to "[email protected]", or that root['items'][5] was deleted. It even handles tricky cases, like ignoring the order of items in a list or treating 1 and 1.0 as equivalent numbers.

The library also includes two companion tools. DeepSearch lets you hunt for a value anywhere inside a complex nested structure—handy when you're looking for where a particular string or object appears. DeepHash creates a fingerprint of any Python object based on its actual contents, even for objects that normally can't be hashed (like dictionaries or lists), which is useful for detecting if two objects are truly identical deep down.

Developers use DeepDiff most often in automated testing. Instead of manually checking that a function's output matches expectations, you can assert that DeepDiff(expected, result) returns an empty result, meaning no differences were found. It's also useful whenever you need to track changes in data—auditing, debugging complex transformations, or validating that two versions of a config file are equivalent except for specific fields you're excluding.

Where it fits