Skip to main content

Versioned Dictionaries

This package implements revision controlled dictionaries. Please see tests.py for usage and a full range of capabilities.

Installation

git clone https://andreacortis@bitbucket.org/andreacortis/versioned_dictionary.git
cd versioned_dictionary
pip install -e .

Usage

In [1]: from versioned_dictionary import VersionedDict, Change

In [2]: D = {'a':1, 'b':{'c':3, 'd':4}}

In [3]: T = VersionedDict(name="my_dict", root_object=D)

In [4]: print(T)

--------------------------------------------------------------------------------
=== VersionedDict ===
name         : my_dict
dict         : {"a": 1, "b": {"c": 3, "d": 4}}
root         : 4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94c
state        : 4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94c
creation time: 2020-04-02 12:00:41.531372
last modified: None

In [5]: print(T['b.c'])
3

In [6]: print(T.root_object)
{'a': 1, 'b': {'c': 3, 'd': 4}}


In [7]: c1 = Change(VersionedDict_root_hash=T.root_hash, state=T.current_state(), verb='set', key='a', to='17')

In [8]: print(c1)
--------------------------------------------------------------------------------
=== CHANGE ===
hash         : 5bfc003ac2c3498e2c997973b6d008b10e9c56e8307db697efa9c075
VersionedDict hash : 4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94c
state        : 4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94c
verb         : set
key          : a
to           : 17
applied      : False
time         : None
old_value    : None
end_state    : None
--------------------------------------------------------------------------------

In [9]: T.apply_change(c1)

In [10]: print(T)
--------------------------------------------------------------------------------
=== VersionedDict ===
name         : my_dict
dict         : {"a": "17", "b": {"c": 3, "d": 4}}
root         : 4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94c
state        : 1def039e9ee1e6e7e266026c0db0101ea51b06266487085775f20454
creation time: 2020-04-02 12:00:41.531372
last modified: 2020-04-02 12:02:33.487806

In [11]: T.apply_change(-c1)

In [12]: print(T)
--------------------------------------------------------------------------------
=== VersionedDict ===
name         : my_dict
dict         : {"a": 1, "b": {"c": 3, "d": 4}}
root         : 4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94c
state        : 4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94c
creation time: 2020-04-02 12:00:41.531372
last modified: 2020-04-02 12:06:01.461169

In [13]: T.revert_to_state('1def039e9ee1e6e7e266026c0db0101ea51b06266487085775f20454')

In [14]: print(T)
--------------------------------------------------------------------------------
=== VersionedDict ===
name         : my_dict
dict         : {"a": "17", "b": {"c": 3, "d": 4}}
root         : 4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94c
state        : 1def039e9ee1e6e7e266026c0db0101ea51b06266487085775f20454
creation time: 2020-04-02 12:00:41.531372
last modified: 2020-04-02 12:06:31.850728


In [15]: print(T.states_history)
['4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94c',
'1def039e9ee1e6e7e266026c0db0101ea51b06266487085775f20454',
'4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94c',
'1def039e9ee1e6e7e266026c0db0101ea51b06266487085775f20454']


In [16]: c2 = Change(VersionedDict_root_hash=T.root_hash, state=T.current_state(),verb='add', key='x', to='333')

In [17]: T.apply_change(c2)

In [18]: print(T)
--------------------------------------------------------------------------------
=== VersionedDict ===
name         : my_dict
dict         : {"a": "17", "b": {"c": 3, "d": 4}, "x": "333"}
root         : 4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94c
state        : d55e3f7557847e880b16e08c58eaffac2fc1ae3a69832ea3f5ae9417
creation time: 2020-04-02 12:00:41.531372
last modified: 2020-04-02 12:07:55.429116


In [19]: c3 = Change(VersionedDict_root_hash=T.root_hash, state=T.current_state(),verb='del', key='a', to='None')

In [20]: T.apply_change(c3)

In [21]: print(T)
--------------------------------------------------------------------------------
=== VersionedDict ===
name         : my_dict
dict         : {"b": {"c": 3, "d": 4}, "x": "333"}
root         : 4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94c
state        : 2ba85ba75a7e67fbe32dd928fd653998f4c0cb534d48c5967d10b9bd
creation time: 2020-04-02 12:00:41.531372
last modified: 2020-04-02 12:08:47.112648

Metadata

Release files for versioned-dictionary 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for versioned-dictionary 0.1.1
File Size Uploaded Provenance Actions
versioned_dictionary-0.1.1.tar.gz 4.8 kB Without provenance Details for versioned_dictionary-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for versioned-dictionary 0.1.1
File Interpreter ABI Platform Actions
versioned_dictionary-0.1.1-py3-none-any.whl Python 3 none any Details for versioned_dictionary-0.1.1-py3-none-any.whl

Total release size: 11.4 kB

Release files / versioned_dictionary-0.1.1.tar.gz

Download URL versioned_dictionary-0.1.1.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
381c7f72012e88e2aa245821492fcba52a75e37abb93ea5fbd0acfe219e7bca9
BLAKE2b-256 checksum
How to use checksums
9734439d96b61d78e2e57b7d2e6682b01e4c58dfdc1c0d389074d74a3eaf6367
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.3

Release files / versioned_dictionary-0.1.1-py3-none-any.whl

Download URL versioned_dictionary-0.1.1-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62a5a7a0af7074433cf2e6b9b945c5743ed3c539e7ad8fab00f5fbe9cfb56167
BLAKE2b-256 checksum
How to use checksums
85ded32d90289cf5c9b800d78279ca674cac9f26de611a646bb625d99880383e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0.post20200106 requests-toolbelt/0.9.1 tqdm/4.40.2 CPython/3.7.3

Security for versioned-dictionary 0.1.1

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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page