Python RevisionDict
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).
It is revision tracking the overall dictionary, but does not store each earlier value for each key in the dictionary. It’s basically answering the following questions:
What is the actual revision number?
What changed since revsion number N?
In which revision has value of key K changed the last time?
Use RevisionDict to build caching systems, interface multiple clients to a common database, publish/subscribe systems,…
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
>>> from revisiondict import RevisionDict >>> 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')
UniqueRevisionDict
UniqueRevisionDict is a subclass of RevisionDict which does not create a new revision, when an element is updated with the same value.
>>> from revisiondict import UniqueRevisionDict >>> d = UniqueRevisionDict(a=0) >>> d.revision 1
>>> d['a']=0 # value is equal to the previous one >>> d.revision 1
>>> d['a']=False # value is still equal as 0 == False >>> d.revision 1
>>> d['a']=100 # a new value is set, so revision is increased >>> d.revision 2
Metadata
Release files for revisiondict 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| revisiondict-1.1.0.tar.gz | 12.6 kB | Without provenance | Details for revisiondict-1.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| revisiondict-1.1.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for revisiondict-1.1.0-py2.py3-none-any.whl |
Total release size: 19.2 kB
Release files / revisiondict-1.1.0.tar.gz
| Download URL | revisiondict-1.1.0.tar.gz |
|---|---|
| Size | 12.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7f5165bf7559e850f46d57c0afaf742df15f80aab9ac2a1770160cb4c36860f9
|
|
BLAKE2b-256 checksum How to use checksums |
d6e07d7dc3bbebf6314a4eedd098c2d9a567c3c822abe7fbb855d2adb54af8ff
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Release files / revisiondict-1.1.0-py2.py3-none-any.whl
| Download URL | revisiondict-1.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 6.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
4ca256d19813f13ff1293550f53c28d2bb28c750d882580a5f696afb8efa3104
|
|
BLAKE2b-256 checksum How to use checksums |
3f0033df6cacee770588a9a0a5766e7d9869fa32ad1018ed953bdff56c38701f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.18
|
Security for revisiondict 1.1.0
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.