io
Modules:
| Name | Description |
|---|---|
serializer_base |
|
serializer_component |
|
serializer_dict |
|
Classes
Modules
serializer_base
Classes:
| Name | Description |
|---|---|
SerializerBase |
This is the base class for creating an encoder/decoder which can |
Classes
SerializerBase
This is the base class for creating an encoder/decoder which can convert EasyScience objects.
encode and decode are abstract methods to be implemented for
each serializer. It is expected that the helper function
_convert_to_dict will be used as a base for encoding (or the
SerializerDict as it's more flexible).
Methods:
| Name | Description |
|---|---|
encode |
Abstract implementation of an encoder. |
decode |
Re-create an EasyScience object from the output of an encoder. |
get_arg_spec |
Get the full argument specification of a function (typically |
deserialize_dict |
Deserialize a dictionary using from_dict for ES objects and |
Functions
encode(obj, skip=None, **kwargs)
abstractmethod
Abstract implementation of an encoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
SerializerComponent
|
Object to be encoded. |
required |
skip
|
Optional[List[str]]
|
List of field names as strings to skip when forming the encoded object. By default, None. |
None
|
**kwargs
|
Any additional key word arguments to be passed to the encoder. |
{}
|
Returns:
| Type | Description |
|---|---|
any
|
Encoded object containing all information to reform an EasyScience object. |
decode(obj)
abstractmethod
classmethod
Re-create an EasyScience object from the output of an encoder.
The default decoder is SerializerDict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Encoded EasyScience object. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Reformed EasyScience object. |
get_arg_spec(func)
staticmethod
Get the full argument specification of a function (typically
__init__)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
Function to be inspected. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Any, List[str]]
|
Tuple of argument spec and arguments. |
deserialize_dict(in_dict)
staticmethod
Deserialize a dictionary using from_dict for ES objects and SerializerBase otherwise. This method processes constructor arguments, skipping metadata keys starting with '@'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_dict
|
Dict[str, Any]
|
Dictionary to deserialize. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Deserialized dictionary with constructor arguments. |
serializer_component
Classes:
| Name | Description |
|---|---|
SerializerComponent |
This base class adds the capability of saving and loading |
Classes
SerializerComponent
This base class adds the capability of saving and loading
(encoding/decoding, serializing/deserializing) easyscience objects
via the encode and decode methods. The default encoder is
SerializerDict, which converts the object to a dictionary.
Shortcuts for dictionary and encoding is also present.
Methods:
| Name | Description |
|---|---|
encode |
Use an encoder to covert an EasyScience object into another |
decode |
Re-create an EasyScience object from the output of an encoder. |
as_dict |
Convert an EasyScience object into a full dictionary using |
from_dict |
Re-create an EasyScience object from a full encoded dictionary. |
Functions
encode(skip=None, encoder=None, **kwargs)
Use an encoder to covert an EasyScience object into another
format. Default is to a dictionary using SerializerDict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skip
|
Optional[List[str]]
|
List of field names as strings to skip when forming the encoded object. By default, None. |
None
|
encoder
|
Optional[SerializerBase]
|
The encoder to be used for encoding the data. By default, None. |
None
|
**kwargs
|
Any additional key word arguments to be passed to the encoder. |
{}
|
Returns:
| Type | Description |
|---|---|
Any
|
Encoded object containing all information to reform an EasyScience object. |
decode(obj, decoder=None)
classmethod
Re-create an EasyScience object from the output of an encoder.
The default decoder is SerializerDict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Encoded EasyScience object. |
required |
decoder
|
Optional[SerializerBase]
|
Decoder to be used to reform the EasyScience object. By default, None. |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Reformed EasyScience object. |
as_dict(skip=None)
Convert an EasyScience object into a full dictionary using
SerializerDict. This is a shortcut for
obj.encode(encoder=SerializerDict)
Parameters
skip : Optional[List[str]], default=None List of field names as strings to skip when forming the dictionary. By default, None.
Returns
Dict[str, Any] Encoded object containing all information to reform an EasyScience object.
from_dict(obj_dict)
classmethod
Re-create an EasyScience object from a full encoded dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj_dict
|
Dict[str, Any]
|
Dictionary containing the serialized contents (from
|
required |
Returns:
| Type | Description |
|---|---|
Any
|
Reformed EasyScience object. |
serializer_dict
Classes:
| Name | Description |
|---|---|
SerializerDict |
This is a serializer that can encode and decode EasyScience objects |
Classes
SerializerDict
This is a serializer that can encode and decode EasyScience objects to and from a dictionary.
Methods:
| Name | Description |
|---|---|
encode |
Convert an EasyScience object to a dictionary. |
decode |
Re-create an EasyScience object from the dictionary |
get_arg_spec |
Get the full argument specification of a function (typically |
deserialize_dict |
Deserialize a dictionary using from_dict for ES objects and |
Functions
encode(obj, skip=None, full_encode=False, **kwargs)
Convert an EasyScience object to a dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
SerializerComponent
|
Object to be encoded. |
required |
skip
|
Optional[List[str]]
|
List of field names as strings to skip when forming the encoded object. By default, None. |
None
|
full_encode
|
bool
|
Should the data also be encoded (default False). By default, False. |
False
|
**kwargs
|
Any
|
Any additional key word arguments to be passed to the encoder. |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Object encoded to dictionary containing all information to reform an EasyScience object. |
decode(d)
classmethod
Re-create an EasyScience object from the dictionary representation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
Dict[str, Any]
|
Dict representation of an EasyScience object. |
required |
Returns:
| Type | Description |
|---|---|
SerializerComponent
|
EasyScience object. |
get_arg_spec(func)
staticmethod
Get the full argument specification of a function (typically
__init__)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
Function to be inspected. |
required |
Returns:
| Type | Description |
|---|---|
Tuple[Any, List[str]]
|
Tuple of argument spec and arguments. |
deserialize_dict(in_dict)
staticmethod
Deserialize a dictionary using from_dict for ES objects and SerializerBase otherwise. This method processes constructor arguments, skipping metadata keys starting with '@'.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_dict
|
Dict[str, Any]
|
Dictionary to deserialize. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Deserialized dictionary with constructor arguments. |