Returns a list of commands/delta to go from one tree of objects to another
Project description
Take 2 sets of containers and provide a (deep) delta between them
This module is used by the author to diff yaml files and on disk file trees and best work out how to transition from one state to another (mainly for work with containers).
Note: Requires Python 3.3 or greater due to use of ‘yield from’
How?
Objdiff uses difflib built into python for lists and tuples (basically sorted things) and implements its own comparison code for dictionaries. User types are detected via the collections.abc.Mapping type and instance comparison and are treated as dictionaries (ie unsorted item => value mappings)
What does this look like?
>>> import objdiff >>> a = {'a': 1, 'b':[1,2,3], 'c':None} >>> b = {'a': 1, 'b':[1,4], 'c':'hello'} >>> objdiff.obj_diff(a, b) <generator object obj_diff at 0xb6a3da80>
We return an iterator and make use of yield from so you can process large trees of objects efficiently and incremental
>>> from pprint import pprint >>> pprint(list(objdiff.obj_diff(a, b))) [modified(path=['c'], old=None, new='hello'), modified(path=['b'], old=[1, 2, 3], new=[1, 4]), equal(path=['a'], old=1, new=1)]
Expanding out the generator we get back a bunch of tuples containing the command value, key path, before and after value
>>> c = {'a':{1: None, 2: 2, 3: 3}, 'b': None} >>> d = {'a':{1: 1, 2: 2}, 'b': {'1':{}, '2':{'2':2}}} >>> pprint(list(objdiff.obj_diff(c, d))) [modified(path=['b'], old=None, new={'1': {}, '2': {'2': 2}}), modified(path=['a', 1], old=None, new=1), equal(path=['a', 2], old=2, new=2), deleted(path=['a', 3], val=3)]
Note: in the above how you get a full list of keys to the destined object after the command value.
In total there are 4 types of command, as listed below with one internal type that can be ignored.
added
deleted
modified
equal (internal, scalar values are equal)
More documentation can be found at Blitz works docs
Changelog
1.2.3 2016-08-26
Actually include module with release
1.2.2 2016-03-28
Split out CHANGELOG to seperate file
Add documentation
Add doctests
Protection against PYTHONHASHSEED randomisation for doctests
objdiff arg names where renamed to make relationship clearer
1.2.1 2016-03-26
Add ‘version guard’ to prevent install on python older than version 3.3
1.2 2016-03-26
Documentation updates
‘deep_update’ function
1.1 2016-03-24
Cleanups of code
Documentation updates
More infrastructure in src module
1.0 2016-03-24
Initial release
Working objdiff
diffing of lists and dicts functions
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file objdiff-1.2.3.zip
.
File metadata
- Download URL: objdiff-1.2.3.zip
- Upload date:
- Size: 29.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c633535f59590704bb34d0de77c555d77ee5a763f11051ef4092d7b2c6c7bf5 |
|
MD5 | 96bc20607a84daf93e22367836af378b |
|
BLAKE2b-256 | 6432be1e217cd3b189158a499d4ff7215b0413e43ea51cbf123574d26e247603 |
File details
Details for the file objdiff-1.2.3.tar.bz2
.
File metadata
- Download URL: objdiff-1.2.3.tar.bz2
- Upload date:
- Size: 17.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca839e7bd7fcba35c953755d7b2262d92f5de11a271051776670676d7bee481e |
|
MD5 | 65e64905d88d3b4c2e249908590acf79 |
|
BLAKE2b-256 | 7813c895a980eeec0595434c940c588c695611806ba09adcd1a9f1ccdb6fc2a0 |
File details
Details for the file objdiff-1.2.3-py2.py3-none-any.whl
.
File metadata
- Download URL: objdiff-1.2.3-py2.py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9355b42502bcfa52e78d34e467b0ddab37d82d89742ace400025d9bfe14d3ba7 |
|
MD5 | deef84d7358b8e60fa3739de4f0ccf51 |
|
BLAKE2b-256 | 888d5e812e6fd8a3db76672a7489a0cf0bdeff3cf273ec49328eda78a20edd6f |