bw2data.backends.json.sync_json_dict
#
Module Contents#
Classes#
A dictionary which stores each value as a separate file on disk. Values are loaded asynchronously (i.e. only as needed), but saved synchronously (i.e. immediately). |
|
A dictionary that can be created but not modified. |
- class bw2data.backends.json.sync_json_dict.SynchronousJSONDict(dirpath, dirname)[source]#
Bases:
collections.abc.MutableMapping
A dictionary which stores each value as a separate file on disk. Values are loaded asynchronously (i.e. only as needed), but saved synchronously (i.e. immediately).
Dictionary keys are strings, and do not correspond with filenames. The utility function safe_filename is used to translate keys into allowable filenames, and a separate mapping dictionary is kept to map dictionary keys to filenames.
Retrieving a key returns a
frozendict
, which can’t be modified. This is to make sure that all changes get synced to disk. To change a dataset you must replace it completely, i.e. this won’t work (it will raise anAttributeError
):my_sync_dict['foo']['bar'] = 'baz'
Instead, you must do:
my_sync_dict['foo'] = {'bar': 'baz'}
After which the ‘foo’ file would be updated.
- class bw2data.backends.json.sync_json_dict.frozendict(*args, **kw)[source]#
Bases:
dict
A dictionary that can be created but not modified.
From http://code.activestate.com/recipes/414283-frozen-dictionaries/
Initialize self. See help(type(self)) for accurate signature.