This quickstart is for people who already understand the basic idea and want to try uv quickly.
It shows a compact workflow for creating a new Python project, adding dependencies, running checks, and syncing the environment.
For detailed explanations, see the earlier chapters in this guide.
This chapter shows how to:
- install
uv, - create a new Python project,
- pin a Python version,
- add development dependencies,
- add a runtime dependency,
- configure
pyproject.toml, - run tests and Ruff,
- synchronize the project environment.
curl -LsSf https://astral.sh/uv/install.sh | shpowershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"Check the installation:
uv --versionCreate a new minimal project:
mkdir example-python-project
cd example-python-project
uv init --bare --name example-python-project --python 3.12Pin the Python version:
uv python pin 3.12At this point, the project should contain:
pyproject.toml
.python-version
The pyproject.toml file describes the Python project.
The .python-version file stores the Python version selected for the project.
Create a basic src/ layout:
mkdir -p src/example_project tests
touch src/example_project/__init__.pyOn Windows PowerShell:
New-Item -ItemType Directory -Force src/example_project
New-Item -ItemType Directory -Force tests
New-Item -ItemType File -Force src/example_project/__init__.pyAdd a simple module:
touch src/example_project/calculator.pyOn Windows PowerShell:
New-Item -ItemType File -Force src/example_project/calculator.pyExample content:
def add(left: int, right: int) -> int:
return left + rightAdd pytest:
uv add --group dev pytestAdd ruff:
uv add --group dev ruffThe project should now contain development dependencies in pyproject.toml.
You should also see or update:
uv.lock
The uv.lock file records the exact resolved dependency versions.
Do not edit uv.lock manually.
These tools are development dependencies.
They are needed while working on the project, but they are not runtime dependencies of the package.
Runtime dependencies are packages needed by the project itself.
For example:
uv add richThis adds rich to the project dependencies.
The runtime dependency should appear in the [project] dependencies section of pyproject.toml.
Development tools such as pytest and Ruff should stay in the development dependency group.
This separation keeps runtime dependencies and development tools easy to understand.
Use runtime dependencies only when the actual package needs them.
Do not add test or linting tools as runtime dependencies.
Open pyproject.toml.
A small configuration may look like this:
[project]
name = "example-python-project"
version = "0.1.0"
requires-python = ">=3.12"
dependencies = [
"rich>=14.0.0",
]
[dependency-groups]
dev = [
"pytest>=8.0.0",
"ruff>=0.11.0",
]
[tool.pytest.ini_options]
testpaths = ["tests"]
pythonpath = ["src"]
[tool.ruff]
line-length = 88
target-version = "py312"
src = ["src", "tests"]
[tool.ruff.lint]
select = [
"E",
"F",
"I",
"B",
"UP",
]The exact dependency versions may be different.
Keep the versions generated by uv.
Create:
tests/test_calculator.py
Example content:
from example_project.calculator import add
def test_add_returns_sum() -> None:
result = add(2, 3)
assert result == 5The project should now contain:
src/example_project/calculator.py
tests/test_calculator.py
The source file contains the function.
The test file verifies the expected behavior.
Run:
uv syncAfter syncing, the project should have a local virtual environment:
.venv/
The .venv/ directory is generated locally.
It should not be committed to Git.
This creates or updates the local virtual environment.
It installs the project dependencies and development dependencies needed for the current project setup.
The local virtual environment is usually stored in:
.venv/
Do not commit .venv/ to Git.
Run tests:
uv run pytestRun Ruff linting:
uv run ruff check .Check formatting:
uv run ruff format --check .Format files automatically:
uv run ruff format .If everything is configured correctly:
uv run pytestshould pass,uv run ruff check .should pass,uv run ruff format --check .should pass.
If the formatting check fails, run:
uv run ruff format .Then run the checks again.
uv updates uv.lock when dependencies change.
You can also update the lockfile explicitly with:
uv lockCommit both:
pyproject.toml
uv.lock
The pyproject.toml file describes dependency requirements.
The uv.lock file stores the exact resolved versions.
For everyday development, use:
uv sync
uv run ruff check .
uv run ruff format --check .
uv run pytestIf formatting fails:
uv run ruff format .
uv run ruff check .
uv run ruff format --check .
uv run pytestCommit:
pyproject.toml
uv.lock
.python-version
src/
tests/
Do not commit:
.venv/
__pycache__/
.pytest_cache/
.ruff_cache/
mkdir example-python-project
cd example-python-project
uv init --bare --name example-python-project --python 3.12
uv python pin 3.12
mkdir -p src/example_project tests
touch src/example_project/__init__.py
touch src/example_project/calculator.py
touch tests/test_calculator.py
uv add --group dev pytest
uv add --group dev ruff
uv add rich
uv sync
uv run ruff check .
uv run ruff format --check .
uv run pytestUse uv to make the project easy to reproduce.
Use pyproject.toml to describe the project.
Use uv.lock to record exact dependency versions.
Use uv run to execute commands inside the project environment.