Sub topic 12
Path, git, and index sources for dependencies
This chapter assumes you can add dependencies with uv add, you know what pyproject.toml and uv.lock are, and you have used pip or a virtual environment before.
Why sources exist
The dependencies list in [project] holds standard requirement strings such as httpx>=0.27. These strings say what you need but not where to get it. By default uv looks for the package on PyPI.
Sometimes the package lives somewhere else. It might be a library in a sibling folder, a branch on GitHub, or a private index. The [tool.uv.sources] table tells uv where to fetch a dependency. The requirement stays in [project], so other tools can still read the file.
The three common source types
| Source | Use it when | Key in the table |
|---|---|---|
| Path | The package is a directory or file on disk | `path` |
| Git | The package is in a git repository | `git` |
| Index | The package comes from a named index other than PyPI | `index` |
Path sources
Use a path source for a local package you are developing alongside your app.
[project]
name = "app"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["core-lib"]
[tool.uv.sources]
core-lib = { path = "../core-lib", editable = true }With editable = true, uv installs the package so that changes to its source files show up without reinstalling. The command uv add --editable ../core-lib writes this entry for you.
Git sources
A git source points at a repository. You can pin it to a branch, a tag, or a commit.
[project]
name = "app"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["httpx"]
[tool.uv.sources]
httpx = { git = "https://github.com/encode/httpx", tag = "0.27.0" }You can also run uv add httpx --git https://github.com/encode/httpx --tag 0.27.0. A tag or a commit hash (rev) is the safest choice. A branch moves, so uv records the exact commit in uv.lock and keeps using it until you run uv lock --upgrade-package httpx.
Index sources
An index source ties a package to a named index. First declare the index, then refer to it by name.
[project]
name = "app"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["torch"]
[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true
[tool.uv.sources]
torch = { index = "pytorch-cpu" }Setting explicit = true means uv uses this index only for packages that name it in [tool.uv.sources]. Without it, uv would also search this index for every other dependency. That is a common way to end up with the wrong package.
How the pieces fit together
Common errors
- Forgetting the requirement. An entry in
[tool.uv.sources]does nothing unless the package is also listed independenciesor a dependency group. - Publishing with path sources.
[tool.uv.sources]is a uv feature. Other tools ignore it and look for the name on PyPI, so a path or git source may not work for people who install your built package. - A relative path that breaks in CI. Paths are relative to the
pyproject.toml. Check that the directory exists in the checkout.
Exercise
You added private-lib to dependencies and a [[tool.uv.index]] entry for your company index, but uv still installs private-lib from PyPI. What is missing, and how would you keep other packages from using that index?
Show answer
Add private-lib = { index = "company" } (using the index's name) under [tool.uv.sources]. Mark the index with explicit = true so only packages that name it are fetched from it.