Back to Prefect

__init__

docs/v3/api-ref/python/prefect-bundles-__init__.mdx

3.7.05.6 KB
Original Source

prefect.bundles

Functions

create_bundle_for_flow_run <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/bundles/__init__.py#L398" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
create_bundle_for_flow_run(flow: Flow[Any, Any], flow_run: FlowRun, context: dict[str, Any] | None = None) -> BundleCreationResult

Creates a bundle for a flow run.

Args:

  • flow: The flow to bundle.
  • flow_run: The flow run to bundle.
  • context: The context to use when running the flow.

Returns:

  • A BundleCreationResult containing:
    • bundle: The serialized bundle
    • zip_path: Path to sidecar zip file if include_files was specified, None otherwise. Caller is responsible for uploading this file and calling cleanup.

extract_flow_from_bundle <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/bundles/__init__.py#L519" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
extract_flow_from_bundle(bundle: SerializedBundle) -> Flow[Any, Any]

Extracts a flow from a bundle.

execute_bundle_in_subprocess <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/bundles/__init__.py#L576" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
execute_bundle_in_subprocess(bundle: SerializedBundle, env: dict[str, str | None] | None = None, cwd: Path | str | None = None) -> multiprocessing.context.SpawnProcess

Executes a bundle in a subprocess.

Args:

  • bundle: The bundle to execute.

Returns:

  • A multiprocessing.context.SpawnProcess.

convert_step_to_command <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/bundles/__init__.py#L667" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
convert_step_to_command(step: dict[str, Any], key: str, quiet: bool = False) -> list[str]

Converts a bundle upload or execution step to a command.

Args:

  • step: The step to convert.
  • key: The key to use for the remote file when downloading or uploading.
  • quiet: Whether to suppress uv output from the command.

Returns:

  • A list of strings representing the command to run the step.

upload_bundle_to_storage <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/bundles/__init__.py#L737" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
upload_bundle_to_storage(bundle: SerializedBundle, key: str, upload_command: list[str], zip_path: Path | None = None, upload_step: dict[str, Any] | None = None) -> None

Uploads a bundle to storage.

Args:

  • bundle: The serialized bundle to upload.
  • key: The key to use for the remote file when uploading.
  • upload_command: The command to use to upload the bundle as a list of strings.
  • zip_path: Optional path to sidecar zip file. If provided, uploads alongside the bundle using the bundle's files_key as the storage key.
  • upload_step: The upload step dict used to build the upload command. Required when uploading a sidecar zip so a separate command with the correct key can be constructed.

aupload_bundle_to_storage <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/bundles/__init__.py#L801" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

python
aupload_bundle_to_storage(bundle: SerializedBundle, key: str, upload_command: list[str], zip_path: Path | None = None, upload_step: dict[str, Any] | None = None) -> None

Asynchronously uploads a bundle to storage.

Args:

  • bundle: The serialized bundle to upload.
  • key: The key to use for the remote file when uploading.
  • upload_command: The command to use to upload the bundle as a list of strings.
  • zip_path: Optional path to sidecar zip file. If provided, uploads alongside the bundle using the bundle's files_key as the storage key.
  • upload_step: The upload step dict used to build the upload command. Required when uploading a sidecar zip so a separate command with the correct key can be constructed.

Classes

BundleLauncherOverride <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/bundles/__init__.py#L54" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

SerializedBundle <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/bundles/__init__.py#L94" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

A serialized bundle is a serialized function, context, and flow run that can be easily transported for later execution.

Attributes:

  • function: Serialized (base64-encoded, gzip-compressed, cloudpickled) flow function.
  • context: Serialized context for flow execution.
  • flow_run: Flow run metadata as a dict.
  • dependencies: Newline-separated list of pip dependencies.
  • files_key: Optional storage key for sidecar zip containing included files. Format: "files/{sha256hash}.zip". None when no files are included.

BundleCreationResult <sup><a href="https://github.com/PrefectHQ/prefect/blob/main/src/prefect/bundles/__init__.py#L115" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>

Result of creating a bundle, including optional sidecar zip info.

Attributes:

  • bundle: The serialized bundle.
  • zip_path: Path to sidecar zip file if include_files was specified. None when no files are included. Caller is responsible for uploading this file and calling cleanup.