py_serializable
Submodules
Attributes
The logger. The thing that captures all this package has to say. |
Classes
Base of all views. |
|
Enum to define the different formats supported for serialization and deserialization. |
|
Enum to differentiate how array-type properties (think Iterables) are serialized. |
|
Enum to differentiate how string-type properties are serialized. |
|
namespace-like |
Functions
Decorator |
|
Decorator used to tell |
|
|
Decorator |
|
Decorator |
|
Decorator |
|
Decorator |
|
Decorator |
|
Decorator |
|
Decorator |
|
Decorator |
|
Decorator |
|
Decorator |
Package Contents
- py_serializable.logger
The logger. The thing that captures all this package has to say. Feel free to modify its level and attach handlers to it.
- class py_serializable.ViewType
Base of all views.
- class py_serializable.SerializationType
Bases:
str,enum.EnumEnum to define the different formats supported for serialization and deserialization.
- JSON = 'JSON'
- XML = 'XML'
- class py_serializable.XmlArraySerializationType
Bases:
enum.EnumEnum to differentiate how array-type properties (think Iterables) are serialized.
Given a
Warehousehas a propertyboxesthat returns List[Box]:FLATwould allow for XML looking like:`` <warehouse>
<box>..box 1..</box> <box>..box 2..</box>
</warehouse> ``
NESTEDwould allow for XML looking like:`` <warehouse>
- <boxes>
<box>..box 1..</box> <box>..box 2..</box>
</boxes>
</warehouse> ``
- FLAT = 1
- NESTED = 2
- class py_serializable.XmlStringSerializationType
Bases:
enum.EnumEnum to differentiate how string-type properties are serialized.
- STRING = 1
as raw string. see https://www.w3.org/TR/xmlschema-2/#string
- NORMALIZED_STRING = 2
as normalizedString. see http://www.w3.org/TR/xmlschema-2/#normalizedString
- TOKEN = 3
as token. see http://www.w3.org/TR/xmlschema-2/#token
- class py_serializable.ObjectMetadataLibrary
namespace-like
The core Class in
py_serializablethat is used to record all metadata about classes that you annotate for serialization and deserialization.- custom_enum_klasses: Set[Type[enum.Enum]]
- klass_mappings: Dict[str, ObjectMetadataLibrary]
- klass_property_mappings: Dict[str, Dict[str, ObjectMetadataLibrary]]
- class SerializableClass(*, klass: type, custom_name: str | None = None, serialization_types: Iterable[SerializationType] | None = None, ignore_during_deserialization: Iterable[str] | None = None, ignore_unknown_during_deserialization: bool = False)
Internal model class used to represent metadata we hold about Classes that are being included in (de-)serialization.
- property name: str
- property klass: type
- property custom_name: str | None
- property serialization_types: Iterable[SerializationType]
- property ignore_during_deserialization: Set[str]
- property ignore_unknown_during_deserialization: bool
- class SerializableProperty(*, prop_name: str, prop_type: Any, custom_names: Dict[SerializationType, str], custom_type: Any | None = None, include_none_config: Set[Tuple[Type[ViewType], Any]] | None = None, is_xml_attribute: bool = False, string_format_: str | None = None, views: Iterable[Type[ViewType]] | None = None, xml_array_config: Tuple[XmlArraySerializationType, str] | None = None, xml_string_config: XmlStringSerializationType | None = None, xml_sequence_: int | None = None)
Internal model class used to represent metadata we hold about Properties that are being included in (de-)serialization.
- property name: str
- property custom_names: Dict[SerializationType, str]
- custom_name(serialization_type: SerializationType) str | None
- property type_: Any
- property concrete_type: Any
- property custom_type: Any | None
- property include_none: bool
- property is_xml_attribute: bool
- property string_format: str | None
- property xml_array_config: Tuple[XmlArraySerializationType, str] | None
- property is_array: bool
- property xml_string_config: XmlStringSerializationType | None
- property is_enum: bool
- property is_optional: bool
- property xml_sequence: int
- is_helper_type() bool
- is_primitive_type() bool
- parse_type_deferred() None
- classmethod defer_property_type_parsing(prop: ObjectMetadataLibrary, klasses: Iterable[str]) None
- classmethod is_klass_serializable(klass: Any) bool
- classmethod is_property(o: Any) bool
- classmethod register_enum(klass: Type[_E]) Type[_E]
- classmethod register_klass(klass: Type[_T], custom_name: str | None, serialization_types: Iterable[SerializationType], ignore_during_deserialization: Iterable[str] | None = None, ignore_unknown_during_deserialization: bool = False) Type[_T] | Type[_JsonSerializable] | Type[_XmlSerializable]
- classmethod register_custom_json_property_name(qual_name: str, json_property_name: str) None
- classmethod register_custom_string_format(qual_name: str, string_format: str) None
- classmethod register_custom_xml_property_name(qual_name: str, xml_property_name: str) None
- classmethod register_property_include_none(qual_name: str, view_: Type[ViewType] | None = None, none_value: Any | None = None) None
- classmethod register_xml_property_array_config(qual_name: str, array_type: XmlArraySerializationType, child_name: str) None
- classmethod register_xml_property_string_config(qual_name: str, string_type: XmlStringSerializationType | None) None
- classmethod register_xml_property_attribute(qual_name: str) None
- classmethod register_xml_property_sequence(qual_name: str, sequence: int) None
- classmethod register_property_type_mapping(qual_name: str, mapped_type: type) None
- py_serializable.serializable_enum(cls: Literal[None] = None) Callable[[Type[_E]], Type[_E]]
- py_serializable.serializable_enum(cls: Type[_E]) Type[_E]
Decorator
- py_serializable.serializable_class(cls: Literal[None] = None, *, name: str | None = ..., serialization_types: Iterable[SerializationType] | None = ..., ignore_during_deserialization: Iterable[str] | None = ..., ignore_unknown_during_deserialization: bool = ...) Callable[[Type[_T]], Type[_T] | Type[_JsonSerializable] | Type[_XmlSerializable]]
- py_serializable.serializable_class(cls: Type[_T], *, name: str | None = ..., serialization_types: Iterable[SerializationType] | None = ..., ignore_during_deserialization: Iterable[str] | None = ..., ignore_unknown_during_deserialization: bool = ...) Type[_T] | Type[_JsonSerializable] | Type[_XmlSerializable]
Decorator used to tell
py_serializablethat a class is to be included in (de-)serialization.- Parameters:
cls – Class
name – Alternative name to use for this Class
serialization_types – Serialization Types that are to be supported for this class.
ignore_during_deserialization – List of properties/elements to ignore during deserialization
ignore_unknown_during_deserialization – Whether to ignore all properties/elements/attributes that are unknown to the class during deserialization
- Returns:
- py_serializable.type_mapping(type_: type) Callable[[_F], _F]
Decorator
- py_serializable.include_none(view_: Type[ViewType] | None = None, none_value: Any | None = None) Callable[[_F], _F]
Decorator
- py_serializable.json_name(name: str) Callable[[_F], _F]
Decorator
- py_serializable.string_format(format_: str) Callable[[_F], _F]
Decorator
- py_serializable.xml_attribute() Callable[[_F], _F]
Decorator
- py_serializable.xml_array(array_type: XmlArraySerializationType, child_name: str) Callable[[_F], _F]
Decorator
- py_serializable.xml_string(string_type: XmlStringSerializationType) Callable[[_F], _F]
Decorator
- py_serializable.xml_name(name: str) Callable[[_F], _F]
Decorator
- py_serializable.xml_sequence(sequence: int) Callable[[_F], _F]
Decorator