serialize
BinaryFileSerializable
Bases: BinarySerializable, FileSerializable
Mixin class enabling serialization of an object to/from a binary file.
Subclasses should override _to_binary_file and _from_binary_file to implement them.
Source code in fancy_dataclass/serialize.py
BinarySerializable
Bases: ABC
Mixin class enabling serialization of an object to/from a binary string.
Subclasses should override _to_bytes and _from_bytes to implement them.
Source code in fancy_dataclass/serialize.py
DictFileSerializableDataclass
Bases: DictDataclass, TextFileSerializable
Mixin class for a DictDataclass capable of serializing its dict representation to some type of file.
Examples include JSON and TOML.
Source code in fancy_dataclass/serialize.py
FileSerializable
Mixin class enabling serialization of an object to/from a file (either text or binary).
Source code in fancy_dataclass/serialize.py
load(file, **kwargs)
classmethod
Deserializes the object from a file, given a path or file-like object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file |
Union[AnyPath, AnyIO]
|
Path or file-like object to load from |
required |
kwargs |
Any
|
Keyword arguments for deserialization |
{}
|
Source code in fancy_dataclass/serialize.py
save(file, **kwargs)
Serializes the object to a path or file-like object (text or binary).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file |
Union[AnyPath, AnyIO]
|
Path or file-like object to save to |
required |
kwargs |
Any
|
Keyword arguments for serialization |
{}
|
Source code in fancy_dataclass/serialize.py
TextFileSerializable
Bases: TextSerializable, BinaryFileSerializable
Mixin class enabling serialization of an object to/from a text file.
Subclasses should override _to_text_file and _from_text_file to implement them.
Source code in fancy_dataclass/serialize.py
TextSerializable
Bases: BinarySerializable, ABC
Mixin class enabling serialization of an object to/from a text string.
Subclasses should override _to_string and _from_string to implement them.
Source code in fancy_dataclass/serialize.py
from_dict_value_basic(tp, val)
Converts a deserialized value to the given type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tp |
type
|
Target type to convert to |
required |
val |
Any
|
Deserialized value |
required |
Returns:
| Type | Description |
|---|---|
Any
|
Converted value |
Source code in fancy_dataclass/serialize.py
to_dict_value_basic(val)
Converts an arbitrary value with a basic data type to an appropriate form for serializing to typical file formats (JSON, TOML).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
val |
Any
|
Value with basic data type |
required |
Returns:
| Type | Description |
|---|---|
Any
|
A version of that value suitable for serialization |