Looking for an introduction to creating a project with uv? See the projects guide first.
Project Structure
A uv project requires apyproject.toml file that defines project metadata and dependencies.
Minimal Project Definition
A minimal project definition includes a name and version:pyproject.toml
Complete Project Structure
A typical uv project includes:- pyproject.toml - Project metadata, dependencies, and configuration
- uv.lock - Universal lockfile with exact package versions
- .venv/ - Virtual environment (auto-managed by uv)
- src/ or flat structure - Python source code
The pyproject.toml File
Python project metadata is defined in apyproject.toml file following the PEP 621 standard. uv uses this file to identify the project root directory.
Project Metadata
Additional project metadata includes:pyproject.toml
Key Metadata Fields
- name - Package name
- version - Package version
- requires-python - Python version requirement
- dependencies - Runtime dependencies
- optional-dependencies - Optional feature dependencies (extras)
Python Version Requirement
Therequires-python field determines:
- Python syntax allowed in the project
- Compatible dependency versions (must support the same Python range)
pyproject.toml
The Project Environment
When working on a project, uv automatically creates and manages a virtual environment.Default Environment Location
By default, uv creates a persistent environment in a.venv directory next to pyproject.toml. The .venv directory:
- Makes it easy for editors to find (for code completions and type hints)
- Is automatically excluded from git (via internal
.gitignore) - Should not be included in version control
Running Commands
To run a command in the project environment:Auto-Sync Behavior
Whenuv run is invoked:
- Creates the project environment if it doesn’t exist
- Ensures the environment is up-to-date with lockfile
- Runs the requested command
Custom Environment Path
TheUV_PROJECT_ENVIRONMENT environment variable configures the virtual environment path:
The Lockfile
uv creates auv.lock file next to pyproject.toml that captures exact package versions.
Universal Lockfile
uv.lock is a universal or cross-platform lockfile that includes packages for all possible Python markers:
- Operating systems (Linux, macOS, Windows)
- Architectures (x86_64, aarch64)
- Python versions (3.9, 3.10, 3.11, etc.)
Lockfile vs pyproject.toml
pyproject.toml
- Broad requirements
- Version constraints
- Manually edited
uv.lock
- Exact versions
- Resolved dependencies
- Auto-managed by uv
Version Control
The lockfile should be checked into version control because it:- Ensures consistent package versions across developers
- Guarantees reproducible installations
- Locks exact versions for production deployments
Auto-Update Behavior
The lockfile is automatically created and updated during:uv sync- Sync environment with lockfileuv run- Run command in project environmentuv lock- Explicitly update lockfile
uv.lock is human-readable TOML but should not be edited manually. It uses a uv-specific format not compatible with other tools.Virtual Environments
Virtual environments isolate project dependencies from the system Python.Creating Environments
The project environment is automatically created when needed:Editable Installation
By default, when the environment is synced, uv installs the project as an editable package:- Source code changes are immediately reflected
- No need to re-sync after editing files
- Uses
.pthfile to link source directory
If the project doesn’t define a build system in
[build-system], it won’t be installed as a package.Managed vs Unmanaged Projects
By default, uv manages the project environment automatically. To disable this:pyproject.toml
managed = false, uv will not automatically lock or sync the project.
Build Systems
A build system determines how the project should be packaged and installed.When to Use Build Systems
You probably need a build system if you want to:- Add command-line interfaces
- Distribute the project to others
- Use a
src/andtest/layout - Write a library
- Writing simple scripts
- Building a basic application
- Using a flat layout
Defining a Build System
pyproject.toml
Build Backend Options
Common build backends include:- hatchling - Modern, fast build backend
- setuptools - Traditional, widely-used
- flit - Lightweight for simple packages
- pdm-backend - PDM’s build backend
Package Setting Override
Override the automatic build system detection:pyproject.toml
Entry Points
Entry points allow installed packages to advertise interfaces.Command-Line Interfaces
Define CLI commands in[project.scripts]:
pyproject.toml
GUI Scripts
Define GUI applications in[project.gui-scripts]:
pyproject.toml
GUI scripts differ from CLI scripts only on Windows, where they’re wrapped by a GUI executable to run without a console.
Plugin Entry Points
Register plugins for discovery:pyproject.toml
Related Documentation
Managing Dependencies
Learn how to add, remove, and manage project dependencies
Python Versions
Understand Python version management and installation
Workspaces
Work with multiple related projects in a single repository
Caching
Learn about uv’s caching mechanisms for faster installs