Sub topic 12
Path, git, and index sources for dependencies
This chapter assumes you can read a pyproject.toml, know how uv add writes to [project].dependencies, and know that uv.lock records resolved versions. By default every dependency comes from PyPI. The [tool.uv.sources] table lets you say "this one comes from somewhere else" without changing what the dependency is called.
Declaring a dependency versus locating it
uv splits two questions that older tools mix together:
- What does the project need?
[project].dependencies(or a dependency group) answers this with a name and a version range, for example"core-lib>=0.1". - Where does uv fetch it from during development?
[tool.uv.sources]answers this, keyed by the same name.
The name must appear in both places. A source entry for a package that no dependency list mentions has no effect.
[project]
name = "app"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
"core-lib>=0.1",
"httpx>=0.27",
]
[tool.uv.sources]
core-lib = { path = "../core-lib", editable = true }
httpx = { git = "https://github.com/encode/httpx", tag = "0.27.0" }Here core-lib is read from a sibling directory and httpx is built from a git tag. Both still satisfy the ranges in dependencies. If the checked-out core-lib were version 0.0.9, resolution would fail.
The split matters when you build and publish. The [tool.uv.sources] table is uv-specific. Build backends and PyPI never see it, so the published metadata only says core-lib>=0.1, and installers resolve that name against an index. Other tools such as pip ignore your sources.
Path sources
A path source points at a directory containing a project, or at a wheel or source archive. Relative paths are resolved from the pyproject.toml that declares them.
[tool.uv.sources]
core-lib = { path = "../core-lib", editable = true }
vendored = { path = "vendor/vendored-1.2.0-py3-none-any.whl" }Without editable = true, uv installs a normal copy, so edits to the source directory do not show up until you re-sync. With it, the environment points at the source tree, which suits code you are actively changing. Workspace members, covered in the previous chapter, are always editable.
You can create the entry from the command line. uv add ../core-lib adds the dependency and the path source together. uv add --editable ../core-lib also sets editable = true.
Git sources
A git source clones a repository and builds the package from it. You can pin it three ways:
[tool.uv.sources]
lib-a = { git = "https://github.com/example/lib-a", tag = "v1.4.0" }
lib-b = { git = "https://github.com/example/lib-b", rev = "3f2a9c1" }
lib-c = { git = "https://github.com/example/lib-c", branch = "main" }
lib-d = { git = "https://github.com/example/mono", subdirectory = "packages/lib-d" }tagandrev(a commit hash) are stable. Prefer them.branchmoves. uv resolves it to a commit when it locks and writes that commit hash intouv.lock. Later syncs use the recorded commit, so the branch can advance without changing your environment. To pick up new commits, runuv lock --upgrade-package lib-c.subdirectoryis for repositories where the package is not at the root.
The command-line form is uv add git+https://github.com/example/lib-a --tag v1.4.0. For private repositories, uv uses your normal git credentials, so SSH URLs and credential helpers work. Do not paste tokens into pyproject.toml, because the file is committed.
URL sources
When the package is a wheel or archive at a fixed address, use url:
[tool.uv.sources]
tool-x = { url = "https://example.com/dist/tool_x-2.0.0-py3-none-any.whl" }The wheel's filename and metadata still have to match the name and version range you declared.
Index sources
Sometimes the package is on a package index, just not the default one. Examples are a company mirror or PyTorch's CPU wheels. You define the index once and then attach packages to it.
[project]
name = "ml-app"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = ["torch>=2.4", "httpx>=0.27"]
[[tool.uv.index]]
name = "pytorch-cpu"
url = "https://download.pytorch.org/whl/cpu"
explicit = true
[tool.uv.sources]
torch = { index = "pytorch-cpu" }explicit = true means only packages that name this index in [tool.uv.sources] are looked up there. Here httpx still comes from PyPI. Without explicit, uv also searches the index for every other package. By default uv uses the first index that has a given package name and does not fall through to later ones. That default protects you from dependency confusion, where a public package with the same name as your internal one wins. Keep it.
Two related keys:
default = truemakes an index replace PyPI as the base index.[[tool.uv.index]]entries are ordered. Earlier entries take priority.
Different sources per platform
A source can be limited with an environment marker, and a dependency can have a list of sources:
[tool.uv.sources]
torch = [
{ index = "pytorch-cpu", marker = "sys_platform == 'linux'" },
{ index = "pytorch-mac", marker = "sys_platform == 'darwin'" },
]Each marker must be disjoint from the others, or uv cannot decide which source applies. Platform splits make the lockfile larger, because uv resolves for each branch.
Common errors
| Symptom | Likely cause |
|---|---|
| A source entry is ignored | The package name is missing from `dependencies` or from a dependency group, or the spelling differs. |
| Resolution fails with a version conflict | The version at the path or git ref does not satisfy your declared range. |
| Edits to a local package do not appear | The path source is missing `editable = true`. |
| A branch dependency does not update | The commit is locked. Run `uv lock --upgrade-package NAME`. |
| A package is found on the wrong index | The index is not `explicit`, or the package has no `index` source. |
| `pip install` of your built wheel fails to find a dependency | The dependency exists only through a uv source. Publish it to an index too. |
The last row is the main practical limit. Sources describe your development environment, not what end users install. Anyone installing your published package needs every dependency to be reachable by name on an index.
Exercise
Your pyproject.toml lists "internal-utils>=2.0" in dependencies and has internal-utils = { git = "https://git.example.com/internal-utils", branch = "main" } in [tool.uv.sources]. A teammate pushes new commits to main, but your environment still has the old code after uv sync. Why, and what do you run to update it? Also, what happens when you publish this project to PyPI and someone runs pip install on it?
Show answer
uv resolved main to a specific commit and recorded it in uv.lock, and uv sync installs what the lockfile says. Run uv lock --upgrade-package internal-utils, then uv sync, to move to the new commit. On PyPI, the source entry is not part of the published metadata. pip sees only internal-utils>=2.0 and looks for it on an index. The install fails unless internal-utils is published somewhere pip can reach.