RevisionDict works like an ordinary dictionary with additional revision keeping of changes.
Project description
Python RevisionDict
RevisionDict works like an ordinary dictionary with additional revision keeping of changes.
Additional functionality compared to dict():
.revision - returning the actual revision as integer (starting with 0)
.key_to_revision(key) - return the revision when the given key was changed
.checkout(start=0) - return a dict with changes older than start
Install
pip install revisiondict
Example
>>> d=RevisionDict() >>> d.revision # get revision (is 0 at init) 0
Adding new items:
>>> d['a']=0; d['b']=1; d['c']=2 # make three updates >>> d.revision # showing 3 changes 3
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['b']=3 # update value of 'b' (was 2 before) >>> d.revision 4 >>> d.key_to_revision('b') 4 >>> d.checkout(3) # get all changes starting with rev. 3 {'b': 3} >>> tuple(d.keys()) # iterate over keys (they are sorted by rev.) ('a', 'c', 'b')
History
0.1.0 (2018-03-24)
First release on PyPI.
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
revisiondict-0.1.1.tar.gz
(15.2 kB
view hashes)
Built Distribution
Close
Hashes for revisiondict-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7dbd963bc19c15dd2a3fad0bffe54bf12719ab7001f93e07c78de545d8f046b |
|
MD5 | 19ef692a7011a1ed7714353a25e56fed |
|
BLAKE2b-256 | a245d2981d0ebd4465099a82887aaa11d419ee50d16c44ca87f3628e004c80fc |