TATECHATLAS
◎ English
Programming / Guide

Describing project metadata and dependencies in pyproject.toml: [build-system], [project] and [tool]

pyproject.toml is a TOML configuration file for packaging tools. This article explains the standardized tables [build-system], [project] and [tool], required versus optional keys, and how the file differs from a pip lock file.

On this page

Write pyproject.toml in TOML. Declare build-time Python dependencies in [build-system] with the mandatory requires list; describe the distribution itself in [project], where only name must be static and version may be static or listed in dynamic; and configure any project tool in [tool] sub-tables you own on PyPI. Keep installation state (pinned versions, hashes) out of pyproject.toml and use pip's repeatable-install mechanisms instead.

The role of pyproject.toml: a TOML configuration with four standardized tables

pyproject.toml is written in TOML and acts as a configuration file for packaging-related tools and, in the [tool] table, for other tools as well. The specification currently defines four tables: [build-system], [project], [dependency-groups] and [tool]. Any other top-level table is reserved for future use, so tool-specific configuration must go under [tool]. It is important to frame the file correctly: pyproject.toml describes the project and how it is built. It does not record what is currently installed in an environment, and it is not a lock file. Mixing those concerns leads to fragile setups, as discussed in the last section.

It is important to frame the file correctly: pyproject.toml describes the project and how it is built. It does not record what is currently installed in an environment, and it is not a lock file. Mixing those concerns leads to fragile setups, as discussed in the last section.

[build-system]requires = [setuptools]

If your build backend computes version or dependencies itself, list those keys in project.dynamic rather than omitting them; this documents the intent and lets back-ends append to list and table keys without removing your static entries.

The [build-system] table: requires and behavior when the table is absent

The [build-system] table declares Python-level dependencies that must be installed for the project's build system to run. Currently only one key is valid and mandatory for the table: requires, a list of strings, each formatted as a dependency specifier. For a setuptools project the canonical example is requires = ["setuptools"]. Tools should not require the table to exist. If pyproject.toml exists but lacks [build-system], tools must apply the default semantics (the setuptools example above), because the file may legitimately hold only non-build configuration. However, if the table is present but missing its required fields, that is an error. Tools may also report an error when the file exists, the table is missing, and there is no other indication that the project should be built, such as a setup.py or a [project] table.

Tools should not require the table to exist. If pyproject.toml exists but lacks [build-system], tools must apply the default semantics (the setuptools example above), because the file may legitimately hold only non-build configuration. However, if the table is present but missing its required fields, that is an error. Tools may also report an error when the file exists, the table is missing, and there is no other indication that the project should be built, such as a setup.py or a [project] table.

[build-system]requires = [setuptools]

Required and optional keys in [project]: name, version and dynamic

The [project] table carries the distribution metadata. The complete allowed key set includes name, version, description, readme, requires-python, license, license-files, authors, maintainers, classifiers, keywords, urls, dependencies, optional-dependencies, entry-points, scripts, gui-scripts, import-names, import-namespaces and dynamic. Only name is required to be statically defined. Version is required but may be either static or listed in dynamic. Everything else is optional: it can be static, listed in dynamic, or omitted. If the whole [project] table is absent, the build backend implicitly provides all keys dynamically.

The rules are asymmetric. Only name is required to be statically defined. Version is required but may be either static or listed in dynamic. Everything else is optional: it can be static, listed in dynamic, or omitted. If the whole [project] table is absent, the build backend implicitly provides all keys dynamically.

Since the PEP 808 update, a key may be both static and in dynamic, but a backend may then only append entries; it must not remove, reorder or modify what you wrote statically.

[project]name = mypackage

Descriptive metadata: description, readme, urls, authors, maintainers, classifiers

description is a one-line string mapping to the Summary metadata field; tools may reject multi-line values. urls is a table of string keys and values, where the key is a URL label and the value the URL, mapping to Project-URL. authors and maintainers are arrays of inline tables with string keys and values, mapping to the Author, Author-email, Maintainer and Maintainer-email fields. classifiers is an array of Trove classifier strings. Note that License :: classifiers are deprecated: tools may warn about them, and build tools may raise an error if both a license expression string and License :: classifiers are used. The modern license key is a string SPDX expression, and license-files is an array of valid glob patterns relative to the project root; an empty license-files array means no license files are included and is not an error.

urls is a table of string keys and values, where the key is a URL label and the value the URL, mapping to Project-URL. authors and maintainers are arrays of inline tables with string keys and values, mapping to the Author, Author-email, Maintainer and Maintainer-email fields.

authors and maintainers are arrays of inline tables with string keys and values, mapping to the Author, Author-email, Maintainer and Maintainer-email fields.

[project]description = A short one-line summary

Runtime dependencies: dependencies as an array of specifiers

readme accepts either a string path relative to pyproject.toml or a table. With a string path, tools must assume UTF-8 encoding: a case-insensitive .md suffix means text/markdown, .rst means text/x-rst, and for any unrecognized suffix without an explicit content-type tools must raise an error. The readme key maps to the Description and Description-Content-Type metadata fields.

Do not confuse these with [build-system].requires. The latter lists what the build tool needs to execute the build (such as setuptools itself); the former lists what your installed package needs at runtime (such as requests). A common mistake is putting a runtime library into build-system requires, which bloats every build environment without making the dependency part of your distribution's metadata.

[project]readme = README.md

The [tool] table: arbitrary tool configuration and the name-ownership rule

license is a string SPDX expression, and license-files is an array of valid glob patterns relative to the project root; an empty license-files array means no license files are included and is not an error. The license key maps to the License-Expression metadata field.

To prevent different projects from colliding on the same sub-table, the specification allocates names with a simple rule: a project may use the tool.$NAME sub-table if and only if it owns the entry for $NAME on PyPI. So you should not invent [tool.mycompany-linter] unless you own that PyPI name; use an existing tool's sub-table or register your own name.

[project]license = MIT

Entry points and their relation to [project]: scripts, gui-scripts, entry-points

The dependencies key is an array of strings, each of which must be a valid dependency specifier and maps directly to a Requires-Dist entry in the core metadata. Every listed dependency is always considered for installation when the distribution is installed.

Two structural rules apply. Users must not create nested sub-tables; entry point groups stay one level deep. And build backends must raise an error if metadata defines [project.entry-points.console_scripts] or [project.entry-points.gui_scripts], because those would be ambiguous against [project.scripts] and [project.gui-scripts].

[project]dependencies = [requests>=2.31,click>=8.1; python_version >= '3.10']

The boundary between pyproject.toml and repeatable pip installs

The [tool] table is where any tool related to your Python project, not only build tools, stores configuration, each in its own sub-table. For example, the flit build tool reads its settings from [tool.flit], and the mypy type checker reads [tool.mypy].

The practical conclusion: keep pyproject.toml about the project (name, version, dependencies as ranges), and express installation state in requirements files or lock-style artifacts. Do not overload pyproject.toml with pinned versions of transitive dependencies.

[tool.mypy]python_version = 3.11strict = true

Things to check

  • Confirm [build-system] is either absent (defaults apply) or contains the mandatory requires list; a present table with missing required fields is an error.
  • Confirm [project] has a static name and that name never appears in dynamic.
  • Confirm every string in dependencies is a valid dependency specifier and that runtime libraries are not mistakenly placed in [build-system].requires.
  • Confirm readme uses .md or .rst, or supplies an explicit content-type table, otherwise tools must error on unrecognized suffixes.
  • Confirm no [project.entry-points.console_scripts] or [project.entry-points.gui_scripts] sub-tables exist alongside [project.scripts]/[project.gui-scripts].
  • Confirm any [tool.$NAME] sub-table corresponds to a PyPI name you own.
  • Keep pinned versions and hashes in requirements files, not in pyproject.toml.

The specification constrains tools, not specific backends; exact behavior of setuptools or flit (for example how they compute dynamic versions) is outside the cited sources. The [dependency-groups] table is listed as standardized but its details are not covered here. pip's repeatability strategies do not remove trust in the index and certificate chain, and wheelhouses are tied to OS and architecture.

Sources

  1. pip: repeatable installs ↗
  2. Python Packaging: pyproject.toml specification ↗
Back to top ↑