Skip to content

Serializer

Bases: ABC, Generic[T]

Turns a queue entry's data into bytes for storage and back.

Implement this to control how AlchemicalQueue/AlchemicalTaskQueue store the item passed to put() (and, for AlchemicalTaskQueue, the response passed to respond()). Pass an instance via the serializer= argument of AlchemicalQueues.get and friends.

Source code in src/alchemical_queues/serializers.py
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
class Serializer(ABC, Generic[T]):
    """Turns a queue entry's data into `bytes` for storage and back.

    Implement this to control how `AlchemicalQueue`/`AlchemicalTaskQueue`
    store the `item` passed to `put()` (and, for `AlchemicalTaskQueue`, the
    `response` passed to `respond()`). Pass an instance via the
    `serializer=` argument of
    [AlchemicalQueues.get][alchemical_queues.AlchemicalQueues.get] and
    friends.
    """

    @abstractmethod
    def dumps(self, obj: T) -> bytes:
        """Serialize `obj` to `bytes` for storage."""

    @abstractmethod
    def loads(self, data: bytes) -> T:
        """Deserialize `data` back into the original object."""

dumps(obj) abstractmethod

Serialize obj to bytes for storage.

Source code in src/alchemical_queues/serializers.py
26
27
28
@abstractmethod
def dumps(self, obj: T) -> bytes:
    """Serialize `obj` to `bytes` for storage."""

loads(data) abstractmethod

Deserialize data back into the original object.

Source code in src/alchemical_queues/serializers.py
30
31
32
@abstractmethod
def loads(self, data: bytes) -> T:
    """Deserialize `data` back into the original object."""