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: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 arequirements.txt file:
Removing Dependencies
Remove a dependency: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:Platform-Specific Dependencies
Use environment markers for platform-specific dependencies: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
Theproject.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
- Common
- Advanced
>=1.2.3- Greater than or equal<2.0- Less than==1.2.3- Exact version!=1.4.0- Not equal
Dependency Sources
Thetool.uv.sources table extends standard dependencies with alternative sources during development.
Why Use Sources?
Sources enable patterns not supported byproject.dependencies:
- Editable installations
- Relative paths
- Git repositories
- Local development versions
Index Sources
Install from a specific package index:pyproject.toml
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:- Tag
- Branch
- Commit
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 objectslfs = false- Never fetch LFS objects- Omitted - Use
UV_GIT_LFSenvironment variable
URL Sources
Install from direct URLs (wheels or source distributions):pyproject.toml
Path Sources
Install from local paths:- Wheel
- Source Distribution
- Directory
pyproject.toml
Editable Path Dependencies
Request editable installation for directories:pyproject.toml
Workspace Sources
Declare dependencies on workspace members:pyproject.toml
Platform-Specific Sources
Limit sources to specific platforms using markers:pyproject.toml
httpx installs from GitHub. On other platforms, it falls back to PyPI.
Multiple Sources
Provide multiple sources disambiguated by environment markers:pyproject.toml
pyproject.toml
Disabling Sources
Ignoretool.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
dev group in [dependency-groups] (PEP 735):
pyproject.toml
The dev Group
Thedev group is special:
- Has dedicated flags:
--dev,--only-dev,--no-dev - Synced by default with
uv syncanduv run
Dependency Groups
Organize development dependencies into multiple groups: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
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
Editable Dependencies
Editable installations link source directories directly into the virtual environment.How Editable Works
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: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
package = false, only bar’s dependencies are installed, not bar itself.
Related Documentation
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