pyproject.toml: Python Project Configuration File
The pyproject.toml file is the standard configuration file for modern Python projects, defined by PEP 518. It serves as a central place to specify project metadata, dependencies, build requirements, and tool configurations.
Tip
Run uv init to scaffold a new project with a pyproject.toml pre-configured with modern defaults. See the uv reference page for more.
Key Aspects
- Single Source: Consolidates project configuration that was historically spread across multiple files like
setup.py,setup.cfg, andrequirements.txt - Standards Compliant: Follows modern Python packaging standards (PEP 517/518/621)
- Tool Agnostic: Works with any compliant build backend or package manager
- TOML Format: Uses TOML for improved readability and reduced syntax errors compared to JSON or INI formats
Core Sections Examples
Project Metadata (PEP 621)
[project]
name = "example"
version = "0.1.0"
description = "A example project"
requires-python = ">=3.8"
dependencies = [
"requests>=2.28.0",
"pandas~=2.0.0",
]Optional Dependencies
[project.optional-dependencies]
dev = ["pytest>=7.0", "ruff"]
docs = ["sphinx", "furo"]Optional dependency groups allow users to install subsets of extras with pip install example[dev] or uv pip install example[docs].
Build System (PEP 517)
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"Tool Configuration
The [tool.*] namespace is reserved for third-party tools to store their configuration. Each tool claims its own sub-table. This eliminates the need for separate config files like .flake8, mypy.ini, or pytest.ini.
[tool.ruff]
line-length = 88
target-version = "py312"
[tool.ruff.lint]
select = ["E", "F", "I"]
[tool.pytest.ini_options]
testpaths = ["tests"]
addopts = "-ra -q"
[tool.mypy]
strict = true
warn_return_any = true
[tool.uv]
dev-dependencies = ["pytest>=7.0.0", "ruff"]Important Fields
[project]
name: Package name on PyPIversion: Package versiondescription: Short project summaryrequires-python: Python version constraintsdependencies: Runtime package requirementsoptional-dependencies: Feature-specific packages
[build-system]
requires: Build system dependenciesbuild-backend: Backend package namebackend-path: Custom backend location
Learn More
- How to migrate from requirements.txt to pyproject.toml with uv
- Why should I choose pyproject.toml over requirements.txt?
- What is PEP 621 compatibility?
- What is PEP 517/518 compatibility?
- Python Packaging User Guide
- PEP 518 - Build System Requirements
- PEP 621 - Project Metadata
- TOML Documentation
- uv - Fast package manager that scaffolds and manages pyproject.toml
- Build backends: Setuptools, Hatch, Flit
Also Mentioned In
- uv: A Complete Guide to Python's Fastest Package Manager
- Ruff: A Complete Guide to Python's Fastest Linter and Formatter
- Getting Started with Python Using Claude Code
- How Python's RFC Process Paved the Way for uv, Ruff, and Ty
- Black: Python Code Formatter
- build: Python Package Build Frontend
- Create your first Python project
- Does Poetry Support Python Standards for Dependency Management?
- Flit: Python Package Build and Publish Tool
- Hatch: Python Project Manager
- How do uv and Poetry compare?
- How to add dynamic versioning to uv projects
- How to change the python version of a uv project
- How to configure mypy strict mode
- How to Fix ModuleNotFoundError: No module named 'numpy' During pip Install
- How to fix Python version incompatibility errors in uv
- How to migrate from mypy to ty
- How to migrate from requirements.txt to pyproject.toml with uv
- How to migrate from setup.py to pyproject.toml
- How to Publish to PyPI with Trusted Publishing
- How to Run a Python REPL with uv
- How to run tests in parallel with pytest-xdist
- How to run the IPython shell in your uv project
- How to sort Python imports with Ruff
- Modern Python Project Setup Guide for AI Assistants
- PDM: Python Package and Dependency Manager
- pip-tools: Python Dependency Pinning Tools
- Poetry: Python Packaging and Dependency Manager
- pylint: Python Static Code Analyzer
- requirements.txt: Python Dependency File Format
- Ruff: Python Linter and Formatter
- sdist: Python Source Distribution Format
- Set up Ruff for formatting and checking your code
- Setting up testing with pytest and uv
- setuptools: Python Package Build Backend
- Understanding dependency groups in uv
- uv: Python Package and Project Manager
- What are Optional Dependencies and Dependency Groups?
- What is a .python-version file?
- What is a build backend?
- What is a PEP?
- What is PEP 517/518 compatibility?
- What is PEP 621 compatibility?
- What is PEP 735?
- Wheel: Python Binary Distribution Format
- Which Python package manager should I use?
- Why should I avoid using the system Python?
- Why Should I Choose pyproject.toml over requirements.txt for managing dependencies?
- Why use native uv commands instead of uv pip
- Why You Should Try uv if You Use Python
Get Python tooling updates
Subscribe to the newsletter