>>> t1 = {1:1, 2:2, 3:3}
>>> t2 = {1:1, 2:"2", 3:3}
>>> printpprint(DeepDiff(t1, t2), indent=2)
{ 'type_changes': ["root[2]{ 'root[2]': 2=<type{ 'newtype': <class 'str'>,
'newvalue': '2',
'oldtype': <class 'int'>,
===> 2=<type 'str'>"] 'oldvalue': 2}}}
>>> t1 = {1:1, 2:2, 3:3}
>>> t2 = {1:1, 2:4, 3:3}
>>> printpprint(DeepDiff(t1, t2), indent=2)
{'values_changed': ['root[2]{'root[2]': 2{'newvalue': ===>4, 4']'oldvalue': 2}}}
>>> t1 = {1:1, 2:2, 3:3, 4:4}
>>> t2 = {1:1, 2:4, 3:3, 5:5, 6:6}
>>> ddiff = DeepDiff(t1, t2)
>>> pprint (ddiff)
{'dic_item_added': ['root[5['root[5]', 6]']'root[6]'],
'dic_item_removed': ['root[4]'],
'values_changed': ['root[2]{'root[2]': 2{'newvalue': ===>4, 4']'oldvalue': 2}}}
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":"world"}}
>>> t2 = {1:1, 2:4, 3:3, 4:{"a":"hello", "b":"world!"}}
>>> ddiff = DeepDiff(t1, t2)
>>> pprint (ddiff, indent = 2)
{ 'values_changed': [{ 'root[2]'root[2]': 2{'newvalue': ===>4, 4''oldvalue': 2},
"root[4]['b']"root[4]['b']": 'world'{ ===>'newvalue': 'world!'"]}
>>>',
>>> print (ddiff['values_changed'][1])
root[4]['b']: 'world' ===> 'world!' 'oldvalue': 'world'}}}
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":"world!\nGoodbye!\n1\n2\nEnd"}}
>>> t2 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":"world\n1\n2\nEnd"}}
>>> ddiff = DeepDiff(t1, t2)
>>> pprint (ddiff, indent = 2)
{ 'values_changed': [{ "root[4]['b']"root[4]['b']":\n" { 'diff': '--- \n'
'--- \n'
'+++ \n'
'@@ -1,5 +1,4 @@\n'
'-world!\n'
'-Goodbye!\n'
'+world\n'
' 1\n'
' 2\n'
' End']End',
'newvalue': 'world\n1\n2\nEnd',
'oldvalue': 'world!\n'
'Goodbye!\n'
'1\n'
'2\n'
'End'}}}
>>>
>>> print (ddiff['values_changed'][0]ddiff['values_changed']["root[4]['b']"]["diff"])
root[4]['b']:
---
+++
@@ -1,5 +1,4 @@
-world!
-Goodbye!
+world
1
2
End
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2, 3]}}
>>> t2 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":"world\n\n\nEnd"}}
>>> ddiff = DeepDiff(t1, t2)
>>> pprint (ddiff, indent = 2)
{ 'type_changes': [{ "root[4]['b']"root[4]['b']": [1,{ 2'newtype': <class 'str'>,
3]=<type 'list'> ===> world\n"
'\n' 'newvalue': 'world\n\n\nEnd',
'\n' 'oldtype': <class 'list'>,
"End=<type 'str'>"] 'oldvalue': [1, 2, 3]}}}
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2, 3, 4]}}
>>> t2 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2]}}
>>> ddiff = DeepDiff(t1, t2)
>>> pprint (ddiff, indent = 2)
{'iterable_item_removed': ["root[4]['b']{"root[4]['b'][2]": [33, 4]"]"root[4]['b'][3]": 4}}
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2, 3]}}
>>> t2 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 3, 2, 3]}}
>>> ddiff = DeepDiff(t1, t2)
>>> pprint (ddiff, indent = 2)
{ 'iterable_item_added': ["root[4]['b']{"root[4]['b'][3]": [3]"]3},
'values_changed': ["root[4]['b'][1]{ "root[4]['b'][1]": 2{'newvalue': ===>3, 3"'oldvalue': 2},
"root[4]['b'][2] "root[4]['b'][2]": 3{'newvalue': ===>2, 2"]'oldvalue': 3}}}
List difference ignoring order or duplicates: (with the same dictionaries as above)
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2, 3]}}
>>> t2 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 3, 2, 3]}}
>>> ddiff = DeepDiff(t1, t2, ignore_order=True)
>>> print (ddiff)
{}
>>> t1 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2, {1:1, 2:2}]}}
>>> t2 = {1:1, 2:2, 3:3, 4:{"a":"hello", "b":[1, 2, {1:3}]}}
>>> ddiff = DeepDiff(t1, t2)
>>> pprint (ddiff, indent = 2)
{ 'dic_item_removed': ["root[4]['b'][2][2]"],
'values_changed': ["root[4]['b'][2][1]{"root[4]['b'][2][1]": 1{'newvalue': ===>3, 3"]'oldvalue': 1}}}
>>> t1 = {1, 2, 8}
>>> t2 = {1, 2, 3, 5}
>>> ddiff = DeepDiff(t1, t2)
>>> printpprint (DeepDiff(t1, t2))
{'set_item_added': ['root: [3['root[3]', 5]']'root[5]'], 'set_item_removed': ['root: [8]']['root[8]']}
>>> from collections import namedtuple
>>> Point = namedtuple('Point', ['x', 'y'])
>>> t1 = Point(x=11, y=22)
>>> t2 = Point(x=11, y=23)
>>> printpprint (DeepDiff(t1, t2))
{'values_changed': ['root{'root.yy': 22{'newvalue': ===>23, 23']'oldvalue': 22}}}
>>> class ClassA(object):
... a = 1
... def __init__(self, b):
... self.b = b
...
>>> t1 = ClassA(1)
>>> t2 = ClassA(2)
>>>
>>> printpprint(DeepDiff(t1, t2))
{'values_changed': ['root{'root.bb': 1{'newvalue': ===>2, 2']'oldvalue': 1}}}
>>> t2.c = "new attribute"
>>> printpprint(DeepDiff(t1, t2))
{'attribute_added': ['root.c'],
'values_changed': ['root{'root.bb': 1{'newvalue': ===>2, 2']'oldvalue': 1}}}