dictutils.ops.deep_diffΒΆ

dictutils.ops.deep_diff(a, b)[source]ΒΆ

Compare two nested structures and return differences.

Parameters:
  • a (Any) – First object to compare

  • b (Any) – Second object to compare

Return type:

tuple[Any, Any, Any, Any]

Returns:

Tuple of (added, removed, changed, same) where each mirrors the input structure

Example

>>> import json
>>> data1 = {"user": {"name": "Alice", "age": 30}, "active": True}
>>> data2 = {"user": {"name": "Alice", "age": 31}, "role": "admin"}
>>> added, removed, changed, same = deep_diff(data1, data2)
>>> print(json.dumps({"added": added, "removed": removed, "changed": changed}, indent=4))
{
    "added": {
        "role": "admin"
    },
    "removed": {
        "active": true
    },
    "changed": {
        "user": {
            "changed": {
                "age": {
                    "from": 30,
                    "to": 31
                }
            },
            "same": {
                "name": "Alice"
            }
        }
    }
}