Module aws_lambda_powertools.utilities.idempotency.serialization.custom_dict

Expand source code
from typing import Any, Callable, Dict

from aws_lambda_powertools.utilities.idempotency.serialization.base import BaseIdempotencySerializer


class CustomDictSerializer(BaseIdempotencySerializer):
    def __init__(self, to_dict: Callable[[Any], Dict], from_dict: Callable[[Dict], Any]):
        """
        Parameters
        ----------
        to_dict: Callable[[Any], Dict]
            A function capable of transforming the saved data object representation into a dictionary
        from_dict: Callable[[Dict], Any]
            A function capable of transforming the saved dictionary into the original data object representation
        """
        self.__to_dict: Callable[[Any], Dict] = to_dict
        self.__from_dict: Callable[[Dict], Any] = from_dict

    def to_dict(self, data: Any) -> Dict:
        return self.__to_dict(data)

    def from_dict(self, data: Dict) -> Any:
        return self.__from_dict(data)

Classes

class CustomDictSerializer (to_dict: Callable[[Any], Dict], from_dict: Callable[[Dict], Any])

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

Parameters

to_dict : Callable[[Any], Dict]
A function capable of transforming the saved data object representation into a dictionary
from_dict : Callable[[Dict], Any]
A function capable of transforming the saved dictionary into the original data object representation
Expand source code
class CustomDictSerializer(BaseIdempotencySerializer):
    def __init__(self, to_dict: Callable[[Any], Dict], from_dict: Callable[[Dict], Any]):
        """
        Parameters
        ----------
        to_dict: Callable[[Any], Dict]
            A function capable of transforming the saved data object representation into a dictionary
        from_dict: Callable[[Dict], Any]
            A function capable of transforming the saved dictionary into the original data object representation
        """
        self.__to_dict: Callable[[Any], Dict] = to_dict
        self.__from_dict: Callable[[Dict], Any] = from_dict

    def to_dict(self, data: Any) -> Dict:
        return self.__to_dict(data)

    def from_dict(self, data: Dict) -> Any:
        return self.__from_dict(data)

Ancestors

Methods

def from_dict(self, data: Dict) ‑> Any
Expand source code
def from_dict(self, data: Dict) -> Any:
    return self.__from_dict(data)
def to_dict(self, data: Any) ‑> Dict
Expand source code
def to_dict(self, data: Any) -> Dict:
    return self.__to_dict(data)