---
name: set-up-python-with-uv
description: Sets up a Python project with uv - install the tool, create pyproject.toml, add packages, write a lockfile, and run commands without activating a venv by hand. Use when the user wants uv, a Python lockfile, or to replace pip and virtualenv for a project.
license: MIT
metadata:
  category: backend
  tags: "uv,python"
  author: johnny-bravo
  version: "1.0"
  updated: "2026-11-07"
  status: published
  aliases: "manage-python-with-uv, uv lock, uv sync, pyproject, requirements.txt, astral uv"
  source_url: "https://github.com/wshobson/agents/tree/7e2fb559cf4b824b27f1fec49fe88f7511066d26/plugins/python-development/skills/uv-package-manager"
  source_license: MIT
  copyright: "Copyright (c) 2024 Seth Hobson"
  original_author: "Seth Hobson (wshobson/agents, uv-package-manager)"
  modified: "Adapted by TheSkillVault: rewritten as a short uv setup (init, add, lock, sync, run) with original commands; dropped the comparison catalogue and advanced source tables; added secret handling, gotchas and done-when."
  imported_on: "2026-11-07"
---

# Set up Python with uv

uv installs Python packages and manages the virtual environment for you. The project file is `pyproject.toml`. The lockfile is `uv.lock`. Commit both.

## When to use
- A repo still uses `pip install` and a checked-in pin file that nobody updates.
- Two machines resolve different versions from the same file.
- You want one command that creates the environment and runs a script.

## When not to use
- You need the shape of an HTTP API. uv does not design routes.
- You need test layout, fixtures and mocks. That is a testing task. uv can install the runner, and that is all.

## Steps
1. Install uv with the official installer, Homebrew (`brew install uv`) or WinGet (`winget install --id=astral-sh.uv -e`). Confirm with `uv --version`.
2. In an empty folder, run `uv init`. This writes `pyproject.toml` and a `.python-version` file. To pin the interpreter, run `uv python pin 3.12`.
3. Add a library with `uv add requests`. Add a dev tool with `uv add --dev ruff`. uv updates `pyproject.toml` and the lockfile, and creates `.venv` if needed.
4. On another machine, or in CI, run `uv sync --frozen` so the install matches `uv.lock` and does not resolve again.
5. Run tools through uv so you do not activate the venv: `uv run python main.py` or `uv run ruff check`.
6. When you want newer versions, run `uv lock --upgrade` and read the diff before you commit it.
7. Ignore `.venv`. Do not ignore `uv.lock`.

```bash
uv init
uv python pin 3.12
uv add requests
uv add --dev ruff
uv sync --frozen
uv run python main.py
```

## Gotchas
- Do not put an index token, password or API key in `pyproject.toml`. Pass private-index credentials through the environment, as uv's docs describe for that index.
- `uv pip install` is a pip-compatible escape hatch. Prefer `uv add` so the lockfile stays the source of truth.
- `uv sync` without `--frozen` may update the lock. In CI, use `--frozen` so a surprise upgrade fails the job.
- Deleting `.venv` is safe. `uv sync` rebuilds it from the lockfile.

## Portability
uv runs on macOS, Linux and Windows. If you use Poetry or pip-tools instead, keep the same rule: one project file, one lockfile, and a frozen install in CI. The commands differ. A Docker image can copy `uv.lock` and run `uv sync --frozen` rather than `pip install`.

## Done when
- `pyproject.toml` and `uv.lock` are committed, and `.venv` is ignored.
- `uv sync --frozen` succeeds on a clean checkout.
- Scripts run with `uv run`, and no secret is written in the project file.

## Example prompt
"Move this repo off pip and a pinned package list. Set it up with uv, pin Python 3.12, and make CI install from the lockfile."

---
Adapted from "uv-package-manager" in wshobson/agents (MIT, Copyright (c) 2024 Seth Hobson). See LICENSE.txt.
