Ready-made Flask virtualenv

Table of Contents

I often build small Flask APIs. Instead of repeating the venv setup in every project, I want a pre-built virtualenv with Flask installed that I can copy into my final image.

1. A Flask virtualenv as a directory artifact

This returns the /app/venv directory with Flask (and optional extra packages) already installed. I can then copy this into any container.

.directory(path) extracts a directory from the container as a Directory artifact. Here it pulls out the fully-built virtualenv so it can be copied into a different, leaner final image without repeating the install steps.

@function
def flask_venv(self, pip_packages: list[str] = ()) -> dagger.Directory:
    """Debian python user venv with flask, exported as directory artifact."""
    ctr = self.debian_python_user_venv(pip_packages=["flask"] + list(pip_packages))
    return ctr.directory("/app/venv")
TMP="${TMP:-$(mktemp -d)}"
dagger call flask-venv export --path="$TMP/out" > /dev/null
test -f "$TMP/out/bin/flask" && echo "bin/flask exists"

Author: root

Created: 2026-04-18 Sat 21:16

Validate