Objdiff
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
Metadata
Release files for objdiff 1.2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distributions (sdists)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| objdiff-1.2.3.zip | 29.6 kB | Without provenance | Details | |
| objdiff-1.2.3.tar.bz2 | 17.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| objdiff-1.2.3-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 54.3 kB
Release files / objdiff-1.2.3.zip
| Download URL | objdiff-1.2.3.zip |
|---|---|
| Size | 29.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6c633535f59590704bb34d0de77c555d77ee5a763f11051ef4092d7b2c6c7bf5
|
|
BLAKE2b-256 checksum How to use checksums |
6432be1e217cd3b189158a499d4ff7215b0413e43ea51cbf123574d26e247603
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / objdiff-1.2.3.tar.bz2
| Download URL | objdiff-1.2.3.tar.bz2 |
|---|---|
| Size | 17.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ca839e7bd7fcba35c953755d7b2262d92f5de11a271051776670676d7bee481e
|
|
BLAKE2b-256 checksum How to use checksums |
7813c895a980eeec0595434c940c588c695611806ba09adcd1a9f1ccdb6fc2a0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Release files / objdiff-1.2.3-py2.py3-none-any.whl
| Download URL | objdiff-1.2.3-py2.py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
9355b42502bcfa52e78d34e467b0ddab37d82d89742ace400025d9bfe14d3ba7
|
|
BLAKE2b-256 checksum How to use checksums |
888d5e812e6fd8a3db76672a7489a0cf0bdeff3cf273ec49328eda78a20edd6f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for objdiff 1.2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.