Skip to main content
Dependencies of a project are defined in several fields in pyproject.toml. uv supports modifying dependencies with uv add and uv remove, or by editing the pyproject.toml directly.

Dependency Fields

Dependencies are organized into different tables:

project.dependencies

Published runtime dependencies

project.optional-dependencies

Published optional dependencies (extras)

dependency-groups

Local development dependencies (PEP 735)

tool.uv.sources

Alternative dependency sources
The project.dependencies and project.optional-dependencies fields can be used even if the project isn’t going to be published. dependency-groups is a recently standardized feature that may not be supported by all tools yet.

Adding Dependencies

Add a dependency to your project:
This updates pyproject.toml:
pyproject.toml

Version Constraints

By default, uv adds a constraint for the most recent compatible version. Customize the bound type:

Importing from requirements.txt

Import dependencies from a requirements.txt file:

Removing Dependencies

Remove a dependency:
Remove from specific tables with flags:

Changing Dependencies

Update an existing dependency’s constraints:
This changes constraints in pyproject.toml. The locked version only changes if necessary to satisfy new constraints. To force an upgrade, use --upgrade-package:
Change dependency source (e.g., to local development version):

Platform-Specific Dependencies

Use environment markers for platform-specific dependencies:
Resulting pyproject.toml:
pyproject.toml

Available Markers

Common environment markers:
  • sys_platform - OS platform (“linux”, “darwin”, “win32”)
  • platform_machine - Architecture (“x86_64”, “aarch64”)
  • python_version - Python version (“3.11”, “3.12”)
  • implementation_name - Python implementation (“cpython”, “pypy”)

Project Dependencies

The project.dependencies table represents dependencies used when:
  • Publishing to PyPI
  • Building wheels
  • Installing the package

Dependency Specifier Syntax

Dependency specifiers follow PEP 508 syntax:
pyproject.toml

Version Specifier Operators

  • >=1.2.3 - Greater than or equal
  • <2.0 - Less than
  • ==1.2.3 - Exact version
  • !=1.4.0 - Not equal
Specifiers can be combined:

Dependency Sources

The tool.uv.sources table extends standard dependencies with alternative sources during development.

Why Use Sources?

Sources enable patterns not supported by project.dependencies:
  • Editable installations
  • Relative paths
  • Git repositories
  • Local development versions
Sources are uv-specific and ignored by other tools. If another tool is used, source metadata must be re-specified in that tool’s format.

Index Sources

Install from a specific package index:
Resulting configuration:
pyproject.toml
Using index source pins the package to that index exclusively.

Explicit Indexes

Mark an index as explicit to use it only for pinned packages:
pyproject.toml

Git Sources

Install from Git repositories:
With specific references:
pyproject.toml

Git Subdirectories

For packages not in the repository root:

Git LFS Support

Configure Git LFS per source:
pyproject.toml
  • lfs = true - Always fetch LFS objects
  • lfs = false - Never fetch LFS objects
  • Omitted - Use UV_GIT_LFS environment variable

URL Sources

Install from direct URLs (wheels or source distributions):
pyproject.toml

Path Sources

Install from local paths:
Path sources support absolute and relative paths:
pyproject.toml

Editable Path Dependencies

Request editable installation for directories:
pyproject.toml
For multiple related packages, consider using workspaces instead.

Workspace Sources

Declare dependencies on workspace members:
pyproject.toml
Workspace members are always editable.

Platform-Specific Sources

Limit sources to specific platforms using markers:
pyproject.toml
On macOS, httpx installs from GitHub. On other platforms, it falls back to PyPI.

Multiple Sources

Provide multiple sources disambiguated by environment markers:
pyproject.toml
Platform-specific indexes:
pyproject.toml

Disabling Sources

Ignore tool.uv.sources (e.g., to test published metadata):

Optional Dependencies

Optional dependencies (extras) reduce the default dependency tree for libraries.

Defining Optional Dependencies

pyproject.toml

Adding Optional Dependencies

Installing with Extras

Users install extras with bracket syntax:

Extra-Specific Sources

Use different sources for different extras:
pyproject.toml

Development Dependencies

Development dependencies are local-only and not published to PyPI.

Adding Development Dependencies

This creates a dev group in [dependency-groups] (PEP 735):
pyproject.toml

The dev Group

The dev group is special:
  • Has dedicated flags: --dev, --only-dev, --no-dev
  • Synced by default with uv sync and uv run

Dependency Groups

Organize development dependencies into multiple groups:
Resulting configuration:
pyproject.toml

Using Groups

The --dev, --only-dev, and --no-dev flags are equivalent to --group dev, --only-group dev, and --no-group dev.

Nesting Groups

Groups can include other groups:
pyproject.toml

Default Groups

Configure which groups are installed by default:
pyproject.toml
Disable defaults during commands:

Group requires-python

Groups can have different Python version requirements:
pyproject.toml

Build Dependencies

Build dependencies are required to build the project, but not to run it.

Defining Build Dependencies

pyproject.toml

Build Dependencies with Sources

By default, tool.uv.sources applies to build dependencies:
pyproject.toml
When publishing, run uv build --no-sources to verify the package builds without custom sources.

Editable Dependencies

Editable installations link source directories directly into the virtual environment.

How Editable Works

1

Regular Installation

Builds wheel, copies files to venv
2

Editable Installation

Adds .pth file linking to source directory
3

Result

Source changes immediately reflected without reinstall

Limitations

  • Build backend must support editable installs
  • Native modules aren’t recompiled before import
  • Some packaging features may not work

Using Editable Dependencies

uv uses editable installation for workspace packages by default. For path dependencies:
Opt-out for workspace members:

Virtual Dependencies

Virtual dependencies don’t install the package itself, only its dependencies.

When to Use

Useful for:
  • Dependency-only projects without installable code
  • Aggregating multiple packages’ dependencies
  • Build-only dependency sets

Marking Dependencies as Virtual

pyproject.toml
With package = false, only bar’s dependencies are installed, not bar itself.

Projects

Learn about project structure and pyproject.toml

Workspaces

Manage dependencies across multiple related packages

Python Versions

Understand how Python versions affect dependency resolution

Cache

Learn how uv caches dependencies