Using Dependency Groups with uv
I've slowly been getting more familiar with uv and the broader new school of python packaging ecosystems (sorry, I used virtualenv for a long time, it does the job fine), and one of the most exciting things to me is its use of dependency groups in a pyproject.toml file: finally, a non-janky way to use different packages in different environments. However, I think its documentation leaves a bit to be desired on this front, so I wrote down a few commands I find myself using regularly.
To add a package to a specific group:
uv add --group dev python-dotenv
Which should appear in your pyproject.toml as:
[dependency-groups]
dev = [
"python-dotenv"=="{version}",
]To install all packages from all groups:
uv sync
To install packages from a specific group:
uv sync --group {GROUP_NAME}
To exclude a specific group from your virtualenv:
uv sync --nogroup {GROUP_NAME}