uv Reproducible Python Environments Prompt
Adopt uv for fast, fully reproducible Python environments — a locked uv.lock, pinned interpreter, dependency groups, and uv run scripts — replacing slow pip/venv/requirements.txt workflows in dev, CI, and Docker.
- Target user
- Python engineers wrangling dependency drift across dev laptops, CI, and containers
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior Python platform engineer who has killed "works on my machine" dependency drift by standardizing on uv for environment management, with a committed lockfile and a pinned interpreter everywhere. I will provide: - My current setup (requirements.txt, pip-tools, Poetry, raw venv) and project layout - Target Python version(s) and whether this is an app or a library - Where it runs (dev, GitHub Actions/GitLab CI, Docker, systemd-timer jobs) Your job: 1. **Project metadata** — produce a `pyproject.toml` with `[project]` dependencies and `[dependency-groups]` (e.g. `dev`, `test`) using uv's group support. For a library, explain the `[build-system]` choice; for an app, note that's optional. 2. **Lock + sync** — explain the `uv lock` → `uv.lock` → `uv sync` flow: the lockfile is committed and fully resolved (hashes, all platforms), `uv sync --frozen` installs exactly it. Contrast with how `requirements.txt` drifts. 3. **Pin the interpreter** — add `.python-version` (or `requires-python`) so uv fetches the exact Python; show `uv python install` and why pinning the interpreter matters as much as pinning deps. 4. **Migrate** — convert my existing requirements/Poetry config into `pyproject.toml` deps and groups; flag any pins that can't be satisfied and any transitive deps I was relying on implicitly. 5. **Running things** — show `uv run <cmd>` (auto-syncs and uses the project env, no manual activate), running tests with `uv run pytest`, and PEP 723 inline-script deps for one-off scripts (`uv run script.py` with a `# /// script` block). 6. **CI** — a GitHub Actions snippet using `astral-sh/setup-uv` with caching, `uv sync --frozen`, then `uv run`. Stress `--frozen` so CI fails if the lock is stale rather than silently re-resolving. 7. **Docker** — a multi-stage Dockerfile using the uv image, `uv sync --frozen --no-dev` for a slim runtime layer, and `--mount=type=cache` for the uv cache. Note `UV_COMPILE_BYTECODE` and copying only `pyproject.toml`+`uv.lock` first for layer caching. Output: (a) `pyproject.toml` with groups, (b) `.python-version`, (c) the migration mapping, (d) CI snippet, (e) the multi-stage Dockerfile, (f) a cheatsheet of daily uv commands. Bias toward: committing uv.lock, `--frozen` in CI/prod, pinning the interpreter, and reproducibility over convenience.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Python Environment Markers & Platform-Conditional Deps Prompt
Author correct PEP 508 environment markers and platform-conditional dependency specifiers so an automation package installs the right wheels per OS, Python version, and architecture without forcing unneeded packages everywhere.
-
Bash Word-Splitting and Quoting Hardening Prompt
Audit and rewrite a Bash script to eliminate unquoted-expansion bugs, unsafe word splitting, and glob injection while preserving intended behavior
-
Bash Exit-Code and Pipefail Propagation Audit Prompt
Audit a Bash script for swallowed failures, missing pipefail, and broken exit-code propagation through pipes, subshells, and command substitution
-
Bash getopts Long-Options Parser Prompt
Build a robust Bash option parser that supports both short flags and GNU-style long options with validation and a generated usage block
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.