Skip to content

Serializers

Artifacts are serialized before being stored in the database. This allows you to store arbitrary data types in your artifacts. You can use the built-in serializers or you can create your own.

Built-in Serializers

Custom Serializers

You can create your own serializer by subclassing artigraph.serializer.Serializer:

from typing import TypeVar

from artigraph.serializer import Serializer

T = TypeVar("T")


class CustomSerializer(Serializer[T]):

    types = (object,)
    """The types that this serializer can handle"""

    def __init__(self):
        # This must be GLOBALLY unique and stable across versions!
        self.name = "custom-serializer"

    def serialize(self, value: T) -> bytes:
        """serialize the value to bytes"""

    def deserialize(self, value: bytes) -> T:
        """deserialize the value from bytes"""


CustomSerializer().register()