gemd.entity.dict_serializable module

class gemd.entity.dict_serializable.DictSerializable

Bases: ABC

A base class for objects that can be represented as a dictionary and serialized.

typ

alias of NotImplementedError

as_dict() Dict[str, Any]

Convert the object to a dictionary.

Returns

A dictionary representation of the object, where the keys are its fields.

Return type

dict

static build(d: Mapping[str, Any]) DictSerializableType

Build an object from a JSON dictionary.

This differs from from_dict in that the values themselves may also be dictionaries corresponding to serialized DictSerializable objects.

Parameters

d (dict) – The object as a serialized dictionary.

Returns

The deserialized object.

Return type

DictSerializable

dump() Dict[str, Any]

Convert the object to a JSON dictionary, so that every entry is serialized.

Uses the json encoder client, so objects with uids are converted to LinkByUID dictionaries.

Returns

A string representation of the object as a dictionary.

Return type

str

classmethod from_dict(d: Mapping[str, Any]) DictSerializableType

Reconstitute the object from a dictionary.

Parameters

d (dict) – The object as a dictionary of key-value pairs that correspond to the object’s fields.

Returns

The deserialized object.

Return type

DictSerializable

skip = {}
class gemd.entity.dict_serializable.DictSerializableMeta(name, bases, *args, typ: Optional[str] = None, skip: Set[str] = frozenset({}), **kwargs)

Bases: ABCMeta

Metaclass for tracking DictSerializable type string to class mappings.

mro()

Return a type’s method resolution order.

register(subclass)

Register a virtual subclass of an ABC.

Returns the subclass, to allow usage as a class decorator.

property class_mapping: Dict[str, type]

Return class typ string -> class map for DictSerializable and its descendants.

Note that is actually returns a copy of the internal dict to avoid accidental breakage.

Returns

The mapping from typ string to class

Return type

Dict[str, type]