Skip to main content

metaflow-prebuilt

A Metaflow extension that pre-bakes conda/PyPI dependencies into Docker images at deploy time. Tasks start immediately — no conda bootstrap overhead at runtime.

How it works

When you deploy a flow with --environment=prebuilt, the extension:

  1. Resolves the conda/PyPI environment spec for each step.
  2. Builds a Docker image with the environment already installed.
  3. Pushes the image to a registry.
  4. Configures the remote runner (Batch, Kubernetes, etc.) to pull that image instead of bootstrapping conda at task start.

Install

pip install metaflow-prebuilt

Optional extras for specific backends:

pip install 'metaflow-prebuilt[ecr]'       # ECR registry + CodeBuild service
pip install 'metaflow-prebuilt[gcr]'       # GCR registry
pip install 'metaflow-prebuilt[kaniko]'    # Kaniko build service (K8s)

Quick start

from metaflow import FlowSpec, step, conda

class MyFlow(FlowSpec):

    @conda(packages={"numpy": "1.26.4"})
    @step
    def start(self):
        import numpy
        print(numpy.__version__)
        self.next(self.end)

    @step
    def end(self):
        pass

if __name__ == "__main__":
    MyFlow()

Deploy with the prebuilt environment (requires a configured registry and build service — see below):

# Deploy: builds and pushes Docker images, then submits the flow
python my_flow.py --environment=prebuilt run

# Or on Batch/Kubernetes:
python my_flow.py --environment=prebuilt batch run

Configuration

Select backends via environment variables:

Variable Default Purpose
METAFLOW_PREBUILT_BUILD_SERVICE docker Which build service to use
METAFLOW_PREBUILT_IMAGE_REGISTRY dockerhub Which image registry to use
METAFLOW_PREBUILT_REGISTRY_CACHE 1 Reuse existing immutable prebuilt image tags when available
METAFLOW_PREBUILT_BUILD_WORKERS min(unique image count, 8) Max concurrent prebuilt image builds

Extension points

DockerBuildService

Controls how Docker images are built and pushed. Select with METAFLOW_PREBUILT_BUILD_SERVICE=<name>.

Name Class Description
docker LocalDockerBuildService Local Docker daemon (docker build + docker push)
buildx BuildxBuildService Docker Buildx (docker buildx build --push), supports remote builders and cross-platform
kaniko KanikoBuildService Kaniko in a Kubernetes Job; uploads context to GCS/S3
codebuild CodeBuildService AWS CodeBuild; uploads context to S3, polls for completion

ImageRegistry

Controls where images are stored. Select with METAFLOW_PREBUILT_IMAGE_REGISTRY=<name>.

Name Class Description
dockerhub DockerHubRegistry Docker Hub (docker.io)
ecr ECRRegistry Amazon ECR
gcr GCRRegistry Google Container Registry
local LocalRegistry Local registry:2 container (dev/CI use)

Contributing a custom backend

Custom build service

Subclass DockerBuildService and implement build_and_push:

from metaflow_extensions.prebuilt.plugins.conda.build_service import DockerBuildService

class MyBuildService(DockerBuildService):
    def build_and_push(self, dockerfile, context_files, image_tag,
                       push_credentials, echo, target_platform=None) -> bool:
        # build and push; return True on success, False on failure.
        # target_platform (e.g. "linux/amd64") is the resolved step's arch for
        # cross-arch builds; None => builder default. Local builders should honor
        # it; remote builders with a fixed build arch may ignore it.
        ...

Register it in your pyproject.toml:

[project.entry-points."metaflow_prebuilt.build_services"]
mybuild = "mypackage.my_module:MyBuildService"

Then use it with METAFLOW_PREBUILT_BUILD_SERVICE=mybuild.

Custom image registry

Subclass ImageRegistry and implement image_tag, push_credentials, and pull_config:

from metaflow_extensions.prebuilt.plugins.conda.image_registry import ImageRegistry

class MyRegistry(ImageRegistry):
    def image_tag(self, env_id) -> str: ...
    def push_credentials(self) -> dict: ...
    def pull_config(self, pull_tag) -> dict: ...

Register it:

[project.entry-points."metaflow_prebuilt.image_registries"]
myregistry = "mypackage.my_module:MyRegistry"

Then use it with METAFLOW_PREBUILT_IMAGE_REGISTRY=myregistry.

License

Apache 2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

metaflow_prebuilt-0.3.4.tar.gz (45.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

metaflow_prebuilt-0.3.4-py2.py3-none-any.whl (53.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file metaflow_prebuilt-0.3.4.tar.gz.

File metadata

  • Download URL: metaflow_prebuilt-0.3.4.tar.gz
  • Upload date:
  • Size: 45.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for metaflow_prebuilt-0.3.4.tar.gz
Algorithm Hash digest
SHA256 702b216bf4a88aa90129da4e200d20e9b9459c8fd2db0424174d5837dc482f0d
MD5 e2c7346e930527d532080cc4c87f0f77
BLAKE2b-256 bd6b0e1963079071e45fb1b6019954a3803e8e641b94fd65f59f6be182a53df2

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaflow_prebuilt-0.3.4.tar.gz:

Publisher: python-publish.yml on Netflix/metaflow-nflx-extensions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file metaflow_prebuilt-0.3.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for metaflow_prebuilt-0.3.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3dea8873aa0b0af4af05b1feddd0749f03fceeecfbb043633578c287c058d8ce
MD5 ca8fc32c0a421dc87a02ebf4d9539e02
BLAKE2b-256 80cd7527875188ad3ba052cd184bb513ca0e260f5d6e332f5a7f85cbf1963e98

See more details on using hashes here.

Provenance

The following attestation bundles were made for metaflow_prebuilt-0.3.4-py2.py3-none-any.whl:

Publisher: python-publish.yml on Netflix/metaflow-nflx-extensions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.3.5

2 files

This release

0.3.4 This release

2 files

0.3.3

2 files

0.3.2

2 files

0.3.1

2 files

0.3.0

2 files

0.2.1

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page