RevisionDict works like an ordinary dictionary with additional revision keeping of changes.
Project description
RevisionDict works like an ordinary dictionary with additional revision keeping of changes. It remembers the order when keys were updated (in contrast to the OrderedDict which is remembering the order when keys are inserted).
Additional functionality compared to dict():
.revision - returning the actual revision as integer (starting with 0)
.base_revision - revision before oldest item changed (or 0 on empty dict)
.key_to_revision(key) - return the revision when the given key was changed
.checkout(start=0) - return a dict with changes since start
Install
pip install revisiondict
Example
>>> d=RevisionDict() >>> d.revision # get revision (is 0 at init) 0 >>> d.base_revision # get revision before oldest change 0
Adding new items:
>>> d['a']=0; d['b']=1; d['c']=2 # make three updates >>> d.revision # showing 3 changes 3 >>> d.base_revision # get revision before oldest change 0
Inspecting content of RevisionDict:
>>> d.checkout()=={'a': 0, 'b': 1, 'c': 2} # get a dictionary with all changes True >>> d.checkout(2) # get all changes starting with rev. 2 {'c': 2} >>> d.checkout(3) # all changes starting with actual revision {} >>> d.key_to_revision('b') # revision where 'b' was changed last time 2 >>> d RevisionDict([_Item(key='a', value=0, revision=1), _Item(key='b', value=1, revision=2), _Item(key='c', value=2, revision=3)])
Update items:
>>> d['a']=3 # update value of 'a' (was 0 before) >>> d.revision 4 >>> d.base_revision 1 >>> d.key_to_revision('a') 4 >>> d.checkout(3) # get all changes starting with rev. 3 {'a': 3} >>> tuple(d.keys()) # iterate over keys (ordered by time of update) ('b', 'c', 'a')
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for revisiondict-0.2.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 80a3354c6faf07c28e92183e7bd8aa4a8bfb2de11d022a97acb8318e85c08784 |
|
MD5 | a2ba3494e4210033065c124ea89bd517 |
|
BLAKE2b-256 | 38f5c5e6c0036b7857ce75f2b03ca44cfdc0c35ea6746ad3960d542c45e50020 |