Skip to content

prefect.packaging.base

PackageManifest

Bases: BaseModel, ABC

Describes a package.

Source code in prefect/packaging/base.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
@add_type_dispatch
class PackageManifest(BaseModel, abc.ABC):
    """
    Describes a package.
    """

    type: str
    flow_name: str
    flow_parameter_schema: ParameterSchema

    @abc.abstractmethod
    async def unpackage(self) -> Flow:
        """
        Retrieve a flow from the package.
        """

unpackage abstractmethod async

Retrieve a flow from the package.

Source code in prefect/packaging/base.py
44
45
46
47
48
@abc.abstractmethod
async def unpackage(self) -> Flow:
    """
    Retrieve a flow from the package.
    """

Packager

Bases: BaseModel, ABC

Creates a package for a flow.

A package contains the flow and is typically stored outside of Prefect. To facilitate interaction with the package, a manifest is returned that describes how to access and use the package.

Source code in prefect/packaging/base.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
@add_type_dispatch
class Packager(BaseModel, abc.ABC):
    """
    Creates a package for a flow.

    A package contains the flow and is typically stored outside of Prefect. To
    facilitate interaction with the package, a manifest is returned that describes how
    to access and use the package.
    """

    type: str

    def base_manifest(self, flow: Flow) -> PartialModel[PackageManifest]:
        manifest_cls = lookup_type(PackageManifest, self.type)
        return PartialModel(
            manifest_cls,
            type=self.type,
            flow_name=flow.name,
            flow_parameter_schema=parameter_schema(flow.fn),
        )

    @abc.abstractmethod
    async def package(self, flow: Flow) -> "PackageManifest":
        """
        Package a flow and return a manifest describing the created package.
        """

package abstractmethod async

Package a flow and return a manifest describing the created package.

Source code in prefect/packaging/base.py
72
73
74
75
76
@abc.abstractmethod
async def package(self, flow: Flow) -> "PackageManifest":
    """
    Package a flow and return a manifest describing the created package.
    """

Serializer

Bases: BaseModel, Generic[D], ABC

A serializer that can encode objects of type 'D' into bytes.

Source code in prefect/packaging/base.py
19
20
21
22
23
24
25
26
27
28
29
30
31
@add_type_dispatch
class Serializer(BaseModel, Generic[D], abc.ABC):
    """
    A serializer that can encode objects of type 'D' into bytes.
    """

    type: str

    def dumps(self, obj: D) -> bytes:
        """Encode the object into a blob of bytes."""

    def loads(self, blob: bytes) -> D:
        """Decode the blob of bytes into an object."""

dumps

Encode the object into a blob of bytes.

Source code in prefect/packaging/base.py
27
28
def dumps(self, obj: D) -> bytes:
    """Encode the object into a blob of bytes."""

loads

Decode the blob of bytes into an object.

Source code in prefect/packaging/base.py
30
31
def loads(self, blob: bytes) -> D:
    """Decode the blob of bytes into an object."""