Package: versioned-dictionary
Versioned DictionariesThis package implements revision controlled dictionaries.
Please seetests.pyfor usage and a full range of capabilities.Installationgitclonehttps://andreacortis@bitbucket.org/andreacortis/versioned_dictionary.gitcdversioned_dictionary
pipinstall-e.UsageIn[1]:fromversioned_dictionaryimportVersionedDict,ChangeIn[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_dictdict:{"a":1,"b":{"c":3,"d":4}}root:4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94cstate:4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94ccreationtime:2020-04-0212:00:41.531372lastmodified:NoneIn[5]:print(T['b.c'])3In[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:5bfc003ac2c3498e2c997973b6d008b10e9c56e8307db697efa9c075VersionedDicthash:4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94cstate:4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94cverb:setkey:ato:17applied:Falsetime:Noneold_value:Noneend_state:None--------------------------------------------------------------------------------In[9]:T.apply_change(c1)In[10]:print(T)--------------------------------------------------------------------------------===VersionedDict===name:my_dictdict:{"a":"17","b":{"c":3,"d":4}}root:4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94cstate:1def039e9ee1e6e7e266026c0db0101ea51b06266487085775f20454creationtime:2020-04-0212:00:41.531372lastmodified:2020-04-0212:02:33.487806In[11]:T.apply_change(-c1)In[12]:print(T)--------------------------------------------------------------------------------===VersionedDict===name:my_dictdict:{"a":1,"b":{"c":3,"d":4}}root:4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94cstate:4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94ccreationtime:2020-04-0212:00:41.531372lastmodified:2020-04-0212:06:01.461169In[13]:T.revert_to_state('1def039e9ee1e6e7e266026c0db0101ea51b06266487085775f20454')In[14]:print(T)--------------------------------------------------------------------------------===VersionedDict===name:my_dictdict:{"a":"17","b":{"c":3,"d":4}}root:4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94cstate:1def039e9ee1e6e7e266026c0db0101ea51b06266487085775f20454creationtime:2020-04-0212:00:41.531372lastmodified:2020-04-0212:06:31.850728In[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_dictdict:{"a":"17","b":{"c":3,"d":4},"x":"333"}root:4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94cstate:d55e3f7557847e880b16e08c58eaffac2fc1ae3a69832ea3f5ae9417creationtime:2020-04-0212:00:41.531372lastmodified:2020-04-0212:07:55.429116In[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_dictdict:{"b":{"c":3,"d":4},"x":"333"}root:4b85a0bcc5e535f29ab263b7691ba7851a9a11b36e65b811e0d0b94cstate:2ba85ba75a7e67fbe32dd928fd653998f4c0cb534d48c5967d10b9bdcreationtime:2020-04-0212:00:41.531372lastmodified:2020-04-0212:08:47.112648