bw2data.backends.json.sync_json_dict#

Module Contents#

Classes#

SynchronousJSONDict

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).

frozendict

A dictionary that can be created but not modified.

class bw2data.backends.json.sync_json_dict.SynchronousJSONDict(dirpath, dirname)[source]#

Bases: collections.abc.MutableMapping

Inheritance diagram of bw2data.backends.json.sync_json_dict.SynchronousJSONDict

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 an AttributeError):

my_sync_dict['foo']['bar'] = 'baz'

Instead, you must do:

my_sync_dict['foo'] = {'bar': 'baz'}

After which the ‘foo’ file would be updated.

_delete_file(key)[source]#

Delete the file associated with key key.

_load_file(key)[source]#

Load the file for key key.

_save_file(key, data)[source]#

Save data data to file for key key.

filepath(key)[source]#

Use bw2data.utils.safe_filename() to get filename for key key.

from_json(data)[source]#

Change exchange inputs from lists to tuples (as there is no distinction in JSON, but Python only allows tuples as dictionary keys).

keys()[source]#

D.keys() -> a set-like object providing a view on D’s keys

class bw2data.backends.json.sync_json_dict.frozendict(*args, **kw)[source]#

Bases: dict

Inheritance diagram of bw2data.backends.json.sync_json_dict.frozendict

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.

_blocked_attribute[source]#
_blocked_attribute()[source]#