pysdic.core.serialization.SerializerMixin#

Note

This class is internal: it is not exported in the pysdic namespace. Its methods are available on all the classes that inherit from it.

Abstract base mixin of the serialization mixins: the subclasses implement to_dict and from_dict.

class SerializerMixin[source]#

Bases: ABC

Base mixin class for serialization and deserialization capabilities. This class serves as a common interface for different serialization formats (e.g., JSON, HDF5, NPZ, …). It defines the abstract methods that subclasses must implement to provide specific serialization logic.

Each subclass should implement the to_dict and from_dict methods to define how the object is represented as a dictionary and how to create an instance from a dictionary, respectively.

Important

The to_dict method should return a dictionary representation of the object, while the from_dict method should take a dictionary as input and return an instance of the class. These methods are essential for enabling the serialization and deserialization processes in the subclasses.

Note

The helper methods of each mixin have format-specific names (_json_*, _hdf5_*, _npz_*) so that a class can inherit from several mixins without one helper shadowing another in the MRO.

abstractmethod classmethod from_dict(data, **kwargs)[source]#

Create an instance of the class from a dictionary representation.

Important

This method should be implemented by subclasses to define how to create an instance from a dictionary.

Parameters:

data (Dict[str, Any])

Return type:

Any

abstractmethod to_dict(**kwargs)[source]#

Convert the object to a dictionary representation.

Important

This method should be implemented by subclasses to define how the object is represented as a dictionary.

Return type:

Dict[str, Any]