REGISTER NOW: Brightway Spring School! 🇨🇦 Québec City (Canada) 🗓️ 20.-24. May 2024

bw2data.serialization#

Module Contents#

Classes#

CompoundJSONDict

Subclass of SerializedDict that allows tuples as dictionary keys (not allowed in JSON).

JsonSanitizer

JsonWrapper

PickledDict

Subclass of SerializedDict that uses the pickle format instead of JSON.

SerializedDict

Base class for dictionary that can be serialized to or unserialized from disk. Uses JSON as its storage format. Has most of the methods of a dictionary.

Attributes#

anyjson

class bw2data.serialization.CompoundJSONDict(dirpath=None)[source]#

Bases: SerializedDict

Inheritance diagram of bw2data.serialization.CompoundJSONDict

Subclass of SerializedDict that allows tuples as dictionary keys (not allowed in JSON).

pack(data)[source]#

Transform the dictionary to a list because JSON can’t handle lists as keys

unpack(data)[source]#

Transform data back to a dictionary

class bw2data.serialization.JsonSanitizer[source]#
classmethod load(data)[source]#
classmethod sanitize(data)[source]#
class bw2data.serialization.JsonWrapper[source]#
classmethod dump(data, filepath)[source]#
classmethod dump_bz2(data, filepath)[source]#
classmethod dumps(data)[source]#
classmethod load(file)[source]#
classmethod load_bz2(filepath)[source]#
classmethod loads(data)[source]#
class bw2data.serialization.PickledDict(dirpath=None)[source]#

Bases: SerializedDict

Inheritance diagram of bw2data.serialization.PickledDict

Subclass of SerializedDict that uses the pickle format instead of JSON.

deserialize()[source]#

Load the serialized data. Can be replaced with other serialization formats.

serialize()[source]#

Method to do the actual serialization. Can be replaced with other serialization formats.

Args:
  • filepath (str, optional): Provide an alternate filepath (e.g. for backup).

class bw2data.serialization.SerializedDict(dirpath=None)[source]#

Bases: collections.abc.MutableMapping

Inheritance diagram of bw2data.serialization.SerializedDict

Base class for dictionary that can be serialized to or unserialized from disk. Uses JSON as its storage format. Has most of the methods of a dictionary.

Upon instantiation, the serialized dictionary is read from disk.

property list[source]#

List the keys of the dictionary. This is a property, and does not need to be called.

backup()[source]#

Write a backup version of the data to the backups directory.

deserialize()[source]#

Load the serialized data. Can be replaced with other serialization formats.

flush()[source]#

Serialize the current data to disk.

keys()[source]#

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

load()[source]#

Load the serialized data. Creates the file if not yet present.

pack(data)[source]#

Transform the data, if necessary. Needed because JSON must have strings as dictionary keys.

random()[source]#

Return a random key.

serialize(filepath=None)[source]#

Method to do the actual serialization. Can be replaced with other serialization formats.

Args:
  • filepath (str, optional): Provide an alternate filepath (e.g. for backup).

unpack(data)[source]#

Return serialized data to true form.

values()[source]#

D.values() -> an object providing a view on D’s values

bw2data.serialization.anyjson[source]#