Sub topic 2
Where uv fits: one tool for projects, Python versions, and tools
This chapter assumes you can write basic Python, use a terminal, and know roughly what pip and virtual environments do. It explains what uv replaces, what it leaves alone, and which commands belong to which job.
The problem uv addresses
A typical Python workflow uses several separate tools:
pyenvor a system installer to get a Python version.python -m venvto create an environment.pipto install packages.pip-toolsor Poetry to lock versions.pipxto run command-line tools.buildandtwineto package and upload.
uv is a single program that covers these jobs. It is written in Rust and reads the standard pyproject.toml file, so your project stays compatible with other tools.
The three jobs of uv
uv groups its commands around three kinds of work.
| Job | What you want | Main commands |
|---|---|---|
| Projects | Manage dependencies, a lockfile, and an environment for your code | `uv init`, `uv add`, `uv lock`, `uv sync`, `uv run` |
| Python versions | Install and select interpreters | `uv python install`, `uv python pin` |
| Tools and scripts | Run command-line tools or one-off scripts | `uvx`, `uv tool`, `uv run script.py` |
A fourth group, uv pip, mimics the pip interface for existing workflows. A later chapter covers it.
What uv manages for you
Inside a project, uv keeps three things in step:
pyproject.tomllists what you asked for, such ashttpx>=0.27.uv.lockrecords the exact versions that were resolved..venvholds the installed packages.
When you run uv run or uv sync, uv checks that the lockfile matches pyproject.toml and that .venv matches the lockfile. It repairs whichever is stale. You rarely activate the environment by hand.
If the required Python version is missing, uv can download it. You do not need to install Python first.
Tools versus project dependencies
Project dependencies belong to your code. Tools such as ruff or httpie are programs you run. Install them separately so they do not pollute your project:
uvx ruff --version
uv tool install httpie
uv python install 3.12uvx runs a tool in a temporary, cached environment. uv tool install keeps it available on your PATH. Neither touches your project's .venv.
What uv does not replace
uv does not change the Python language or the packaging standards. It installs from PyPI, builds standard wheels, and reads standard metadata. Its own settings live under the [tool.uv] table, which other tools ignore.
Common mistakes
- Running
pip installinside a uv project. This changes.venvwithout updatingpyproject.tomloruv.lock. Useuv addinstead. - Editing the dependency list in
pyproject.tomland forgetting the lockfile.uv runanduv syncrefresh it for you, but CI with--lockedwill fail until you do. - Installing a development tool as a project dependency when it should be a tool or a dependency group.
Exercise
You want to try ruff once without adding it to your project, and you want your project's pyproject.toml and uv.lock to stay unchanged. Which command do you use, and why?
Show answer
Use uvx ruff. It runs ruff in a temporary cached environment, so it does not modify pyproject.toml, uv.lock, or the project's .venv. uv add ruff would change all three.
Exercise
Name the three files or directories uv keeps in sync inside a project, and say which one records exact resolved versions.
Show answer
pyproject.toml, uv.lock, and .venv. The uv.lock file records the exact resolved versions.