Sub topic 6
Development dependencies and dependency groups
This chapter assumes you can create a project with uv init, add runtime dependencies with uv add, and read the [project] table in pyproject.toml. It covers how to keep tools such as test runners and linters out of the dependencies your users install.
Why separate development dependencies
Runtime dependencies belong in [project] dependencies. They are published in the package metadata, so anyone who installs your package gets them. Tools like pytest are different. You need them while working on the project, but your users do not.
A dependency group is a named list of packages stored in the [dependency-groups] table. Groups are not part of the published metadata. They exist for the people working on the project.
Adding a development dependency
uv add --dev pytestThis writes the package into the dev group:
[dependency-groups]
dev = ["pytest>=8"]You can create any other group with --group:
uv add --group lint ruff
uv add --group docs mkdocs[dependency-groups]
dev = ["pytest>=8"]
lint = ["ruff>=0.6"]
docs = ["mkdocs>=1.6"]To remove a package from a group, pass the same flag to uv remove:
uv remove --group lint ruffWhich groups are installed
The dev group is special. By default, uv sync and uv run install it along with the runtime dependencies. Other groups are skipped unless you ask for them.
| Flag | Effect |
|---|---|
| `--group docs` | Include the `docs` group in addition to the defaults |
| `--only-group lint` | Install only the `lint` group, without the project's own dependencies |
| `--no-dev` | Leave out the `dev` group |
| `--all-groups` | Include every group |
uv sync --group docs
uv run --only-group lint ruff check .
uv sync --no-devKeeping groups in the lockfile
All groups are resolved together into one uv.lock, whether or not you install them. The lockfile therefore records one consistent set of versions. A group cannot pull in a version of a shared package that conflicts with your runtime dependencies.
Setting default groups
If you want docs installed by default as well, list it under [tool.uv]:
[tool.uv]
default-groups = ["dev", "docs"]Groups can also include one another:
[dependency-groups]
test = ["pytest>=8"]
dev = [{ include-group = "test" }, "ruff>=0.6"]Common mistakes
- Putting
pytestin[project] dependencies. Your users then install it. - Using the older
[tool.uv] dev-dependenciesfield in new projects.[dependency-groups]is the standard and is whatuv add --devwrites. - Expecting
uv syncto install a non-default group. Pass--groupor setdefault-groups.
Exercise
You run uv add --group lint ruff, then uv sync. Is ruff installed in the environment? How would you install it, and how would you run ruff without installing the project's runtime dependencies?
Show answer
No. lint is not a default group, so plain uv sync skips it. Run uv sync --group lint to install it in addition to the defaults, or add lint to default-groups under [tool.uv]. To run ruff alone, use uv run --only-group lint ruff check ..