Python › Modules & Packaging
How does pyproject.toml serve as the modern standard for defining a Python package's build configuration and dependencies?
IntermediateAnswer
pyproject.toml (PEP 518/621) is the standardized configuration file that specifies build-system requirements (like setuptools or poetry), project metadata (name, version, dependencies), and tool-specific configuration (black, pytest, mypy) in one place, replacing the older, less standardized combination of setup.py, setup.cfg, and various tool config files.
# pyproject.toml
[project]
name = "mypackage"
version = "1.0.0"
dependencies = ["requests>=2.28", "click>=8.0"]
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"Real-world example A new open-source project adopts pyproject.toml exclusively, avoiding a legacy setup.py entirely, and configures both its build system and its black/pytest settings in the same file.