Python dependency management

Table of Contents

I manage Python dependencies with pip-tools (pip-compile and pip-sync). I need a ready-made container with these tools installed and a non-root user.

1. A pip-tools container

Based on the Python version set in Lib.pip_tools_python_version, with pip-tools installed and a default user. This composes .from_, use_user, and .with_exec — the same primitives described in the Alpine and user docs.

This intentionally uses python:{version}-alpine directly instead of alpine_python(), because pip-compile output depends on the exact Python version and alpine_python() gives whatever Python ships with the Alpine release.

@function
def pip_tools(self) -> dagger.Container:
    """Python Alpine with pip-tools and a default user."""
    ctr = dag.container().from_(self.pinned(self._pip_tools_image))
    ctr = self.use_user(ctr)
    return ctr.with_exec(["pip", "--quiet", "install", "pip-tools"])
dagger call pip-tools with-exec --args="which","pip-compile" stdout

2. Image reference for pin management

See alpine for the convention.

@property
def _pip_tools_image(self) -> str:
    return f"python:{self.pip_tools_python_version}-alpine"

Author: root

Created: 2026-04-18 Sat 21:16

Validate