Deserializer#

class pymc_marketing.deserialize.Deserializer(is_type, deserialize)[source]#

Object to store information required for deserialization.

All deserializers should be stored via the register_deserialization() function instead of creating this object directly.

Attributes:
is_typeIsType

Function to determine if the data is of the correct type.

deserializeDeserialize

Function to deserialize the data.

Examples

from typing import Any

class MyClass:
    def __init__(self, value: int):
        self.value = value

from pymc_marketing.deserialize import Deserializer

def is_type(data: Any) -> bool:
    return data.keys() == {"value"} and isinstance(data["value"], int)

def deserialize(data: dict) -> MyClass:
    return MyClass(value=data["value"])

deserialize_logic = Deserializer(is_type=is_type, deserialize=deserialize)

Methods

Deserializer.__init__(is_type, deserialize)

Attributes

is_type

deserialize