Module aws_lambda_powertools.utilities.idempotency.serialization.base

Serialization for supporting idempotency

Expand source code
"""
Serialization for supporting idempotency
"""
from abc import ABC, abstractmethod
from typing import Any, Dict


class BaseIdempotencySerializer(ABC):
    """
    Abstract Base Class for Idempotency serialization layer, supporting dict operations.
    """

    @abstractmethod
    def to_dict(self, data: Any) -> Dict:
        raise NotImplementedError("Implementation of to_dict is required")

    @abstractmethod
    def from_dict(self, data: Dict) -> Any:
        raise NotImplementedError("Implementation of from_dict is required")


class BaseIdempotencyModelSerializer(BaseIdempotencySerializer):
    """
    Abstract Base Class for Idempotency serialization layer, for using a model as data object representation.
    """

    @classmethod
    @abstractmethod
    def instantiate(cls, model_type: Any) -> BaseIdempotencySerializer:
        """
        Creates an instance of a serializer based on a provided model type.
        In case the model_type is unknown, None will be sent as `model_type`.
        It's on the implementer to verify that:
        - None is handled correctly
        - A model type not matching the expected types is handled

        Parameters
        ----------
        model_type: Any
            The model type to instantiate the class for

        Returns
        -------
        BaseIdempotencySerializer
            Instance of the serializer class
        """
        pass

Classes

class BaseIdempotencyModelSerializer

Abstract Base Class for Idempotency serialization layer, for using a model as data object representation.

Expand source code
class BaseIdempotencyModelSerializer(BaseIdempotencySerializer):
    """
    Abstract Base Class for Idempotency serialization layer, for using a model as data object representation.
    """

    @classmethod
    @abstractmethod
    def instantiate(cls, model_type: Any) -> BaseIdempotencySerializer:
        """
        Creates an instance of a serializer based on a provided model type.
        In case the model_type is unknown, None will be sent as `model_type`.
        It's on the implementer to verify that:
        - None is handled correctly
        - A model type not matching the expected types is handled

        Parameters
        ----------
        model_type: Any
            The model type to instantiate the class for

        Returns
        -------
        BaseIdempotencySerializer
            Instance of the serializer class
        """
        pass

Ancestors

Subclasses

Static methods

def instantiate(model_type: Any) ‑> BaseIdempotencySerializer

Creates an instance of a serializer based on a provided model type. In case the model_type is unknown, None will be sent as model_type. It's on the implementer to verify that: - None is handled correctly - A model type not matching the expected types is handled

Parameters

model_type : Any
The model type to instantiate the class for

Returns

BaseIdempotencySerializer
Instance of the serializer class
Expand source code
@classmethod
@abstractmethod
def instantiate(cls, model_type: Any) -> BaseIdempotencySerializer:
    """
    Creates an instance of a serializer based on a provided model type.
    In case the model_type is unknown, None will be sent as `model_type`.
    It's on the implementer to verify that:
    - None is handled correctly
    - A model type not matching the expected types is handled

    Parameters
    ----------
    model_type: Any
        The model type to instantiate the class for

    Returns
    -------
    BaseIdempotencySerializer
        Instance of the serializer class
    """
    pass
class BaseIdempotencySerializer

Abstract Base Class for Idempotency serialization layer, supporting dict operations.

Expand source code
class BaseIdempotencySerializer(ABC):
    """
    Abstract Base Class for Idempotency serialization layer, supporting dict operations.
    """

    @abstractmethod
    def to_dict(self, data: Any) -> Dict:
        raise NotImplementedError("Implementation of to_dict is required")

    @abstractmethod
    def from_dict(self, data: Dict) -> Any:
        raise NotImplementedError("Implementation of from_dict is required")

Ancestors

  • abc.ABC

Subclasses

Methods

def from_dict(self, data: Dict) ‑> Any
Expand source code
@abstractmethod
def from_dict(self, data: Dict) -> Any:
    raise NotImplementedError("Implementation of from_dict is required")
def to_dict(self, data: Any) ‑> Dict
Expand source code
@abstractmethod
def to_dict(self, data: Any) -> Dict:
    raise NotImplementedError("Implementation of to_dict is required")