Sub topic 1
What pyproject.toml describes
Prerequisites
This chapter assumes you can write basic Python, use a terminal, and import packages. It also assumes you know roughly what pip and virtual environments do. You don't need to have installed uv yet.
One file, several tables
pyproject.toml is a TOML file at the root of a Python project. It holds project metadata, dependencies, build settings, and tool configuration in one place. TOML is a plain-text format built from [table] headings and key = value lines.
Each table has a separate purpose and a separate reader. The table below shows the four that this tutorial uses most.
| Table | What it holds | Who reads it |
|---|---|---|
| `[project]` | Name, version, Python requirement, runtime dependencies, entry points | Any packaging tool, including uv and pip |
| `[dependency-groups]` | Named lists of dependencies that are not shipped, such as `dev` | uv, pip, and other tools that support the standard |
| `[build-system]` | The backend that turns your source into a wheel or sdist | Build frontends such as `uv build` and `pip` |
| `[tool.uv]` | Settings that only uv understands, such as sources and workspaces | uv only |
The first three tables are defined by Python packaging standards. [tool.*] tables are free-form space for individual tools, so [tool.uv] is not portable to other tools.
A complete example
This file describes a small command-line project named weather-cli.
[project]
name = "weather-cli"
version = "0.1.0"
description = "Print the weather from the command line"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"httpx>=0.27",
"typer>=0.12",
]
[project.scripts]
weather = "weather_cli:main"
[dependency-groups]
dev = ["pytest>=8"]
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"Reading it from the top:
nameandversionidentify the package. The name is what users type afterpip installoruv add.requires-pythonstates which interpreters can run the code. uv uses it when it picks a Python version and when it resolves dependencies.dependencieslists what the code needs at runtime. Each entry is a name plus an optional version constraint, such ashttpx>=0.27.[project.scripts]creates a command. Installing the package makes aweathercommand that calls themainfunction in theweather_climodule.[dependency-groups]keepspytestout of the runtime dependencies. Users who install your package don't receive it.[build-system]nameshatchlingas the backend that builds the package.
Common errors
- Missing
[build-system]. Without it, tools fall back to a legacy setuptools build. uv may then treat the project as an application that is not installed into its own environment. Add the table when you want a real package. - Putting dev tools in
dependencies. Anything listed there is installed for every user. Use a dependency group. - Putting uv settings in
[project]. Keys that the standard doesn't define are errors. uv-specific settings belong under[tool.uv]. - Mismatched entry point. The value in
[project.scripts]must bemodule:function. A typo shows up only when you run the command.
Exercise
You want pytest available while developing, but you don't want it installed when someone installs your package. Which table should list it, and why not [project] dependencies?
Show answer
List it in [dependency-groups], for example dev = ["pytest>=8"]. Entries in [project] dependencies are runtime requirements, so every user who installs the package would receive them.