Serialization / Deserialization#

Base classes#

class wayflowcore.serialization.serializer.SerializableObject(__metadata_info__=None, id=None)#

Abstract base class for WayFlow components that can be serialized and deserialized.

This class provides a common interface for objects that need to be converted to and from a dictionary representation.

Parameters:
  • __metadata_info__ (Dict[str, Any] | None) –

  • id (str | None) –

classmethod get_component(component_type)#
Parameters:

component_type (str) –

Return type:

Type[SerializableObject]

Serialization#

wayflowcore.serialization.serializer.serialize(obj)#

Serializes an object into a YAML string representation.

Parameters:

obj (SerializableObject) – Object to serialize.

Return type:

A YAML string representation of the object.

Examples

>>> from wayflowcore.serialization.serializer import serialize
>>>
>>> serialized_assistant_as_str = serialize(assistant)

Deserialization#

wayflowcore.serialization.serializer.deserialize(deserialization_type, obj, deserialization_context=None)#

Deserializes an object from its text representation and its corresponding class.

Parameters:
  • deserialization_type (type[~T]) – The type of the object to be deserialized.

  • obj (str) – The text representation of the object to be deserialized.

  • deserialization_context (DeserializationContext | None) – Context for deserialization operations, to avoid deserializing a same object twice. If not provided, a new DeserializationContext will be created.

Return type:

The deserialized object.

Examples

>>> from wayflowcore.serialization.serializer import deserialize
>>> from wayflowcore.flow import Flow
>>>
>>> new_assistant = deserialize(Flow, serialized_assistant_as_str)
wayflowcore.serialization.serializer.autodeserialize(obj, deserialization_context=None)#

Deserializes an object from its text representation.

Parameters:
  • obj (str) – The text representation of the object to be deserialized.

  • deserialization_context (DeserializationContext | None) – Context for deserialization operations, to avoid deserializing a same object twice. If not provided, a new DeserializationContext will be created.

Return type:

The deserialized object.

Examples

>>> from wayflowcore.serialization.serializer import autodeserialize
>>>
>>> new_assistant = autodeserialize(serialized_assistant_as_str)