- Install
uv
:
$ curl -LsSf https://astral.sh/uv/install.sh | sh
- Create a new project (with the
--lib
option):
$ uv init --lib uv-demo
Tip
The --lib
option specifies the build-system
for us in pyproject.toml
and creates the project in the src layout.
- Add dependencies (
requests
,polars
,pytest
,ruff
)- Note: Add
pytest
andruff
under thedev
group.
- Note: Add
$ uv add requests
$ uv add polars
$ uv add --dev pytest
$ uv add --dev ruff
Those commands added the following sections to our initial pyproject.toml
file, and created/updated a uv.lock
file.
[project]
name = "uv-demo"
version = "0.1.0"
description = ""
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"polars>=1.6.0",
"requests>=2.32.3",
]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.uv]
dev-dependencies = [
"pytest>=8.3.2",
"ruff>=0.6.3",
]
-
Add code (
demo.py
,__init__.py
,__main__.py
) and tests (test_demo.py
). -
Run tests and lint/format code:
$ uv run pytest
$ uv run ruff check --fix
$ uv run ruff format
- Run the app:
$ uv run python -m uv_demo
Or, add the following section to pyproject.toml
:
[project.scripts]
"uv-demo" = "uv_demo:main"
to run it more directly:
$ uv run uv-demo
- Add uv-based GH workflow to lint and run tests.