TATECHATLAS
◎ English
Programming / Guide

Describing project metadata and dependencies in pyproject.toml

pyproject.toml is a TOML configuration file for packaging tools. Learn how [build-system], [project] and [tool] tables, dependencies and entry points fit together, and how they relate to repeatable pip installs.

On this page

Use pyproject.toml as the single TOML configuration for packaging: [build-system] with a mandatory requires list declares what is needed to run the build; [project] holds static metadata such as name, requires-python, license (SPDX string), readme, classifiers, urls and dependencies; entry points are declared in [project.scripts], [project.gui-scripts] and [project.entry-points]; dynamic lists keys a backend may fill in, with name excluded and static values protected from modification; [tool.$NAME] holds per-tool configuration for names you own on PyPI. Pair these declarations with pip pinning, hash-checking and wheelhouses for repeatable installs.

Role of pyproject.toml and the three standard tables

pyproject.toml is a configuration file written in TOML that packaging-related tools (and other tools) read. The formal specification currently defines three tables: [build-system], [project] and [tool]. Any other top-level table is reserved for future use, so tool-specific configuration must live under [tool]. The mental model is layered: [build-system] tells the installer what it needs to build the project, [project] describes the distribution itself (name, Python requirement, license, dependencies, entry points), and [tool] is free space for individual tools. Keeping these layers separate matters because a file can legitimately exist without [build-system] when it only stores tool configuration.

[build-system]
requires = ["setuptools>=68"]
build-backend = "setuptools.build_meta"

[project]
name = "example-package"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = []

[tool.black]
line-length = 88

Keep [build-system] requires minimal and put runtime needs in [project] dependencies; when a key must be computed by the backend, list it in dynamic rather than omitting it silently, and remember name can never be dynamic.

The [build-system] table: declaring build dependencies

The [build-system] table declares Python-level dependencies that must be installed for the project's build system to run. Only one key is currently valid and mandatory for the table: requires, a list of strings following the dependency specifier format. For a setuptools-based project the table is simply requires = [

[build-system]
requires = ["setuptools>=68"]
build-backend = "setuptools.build_meta"

Required and static metadata in [project]

The [project] table carries the distribution's static metadata. The name key identifies the project. requires-python is a string describing the Python versions the project supports and maps to the Requires-Python metadata field. The license key takes a text string that must be a valid SPDX license expression; tools should validate and case-normalize it. The legacy table form of license (with file or text keys) is deprecated. The readme key accepts either a plain string path or a table with file or text keys (mutually exclusive) plus a content-type; tools infer text/markdown from .md and text/x-rst from .rst, and must raise an error for unrecognized suffixes without an explicit content-type. classifiers holds trove classifiers, but License:: classifiers are deprecated and tools may warn or error when they coexist with the license expression. urls is a table of label-to-URL pairs mapped to Project-URL entries.

[project]
name = "example-package"
version = "0.1.0"
requires-python = ">=3.10"
license = "MIT"
readme = "README.md"

Dependencies: the dependencies key and specifier format

The dependencies key is an array of strings, each formatted as a valid dependency specifier, and each string maps directly to a Requires-Dist entry in the core metadata. Dependencies listed here are always considered for installation, even though a specifier may contain environment markers that limit when a given dependency actually applies. This is the declarative core of the file: it says what the package needs at runtime, separate from the build-time needs in [build-system]. A common mistake is putting build tools like setuptools or wheel into dependencies; they belong in [build-system] requires, since end users installing your package do not need them.

[project]
name = "example-package"
version = "0.1.0"
dependencies = [
    "requests>=2.31",
    "packaging>=23",
]

Entry points: scripts, gui-scripts and entry-points

Three tables define entry points. [project.scripts] corresponds to the console_scripts group: each key is the entry point name and each value is an object reference like module:function. [project.gui-scripts] has the same format but maps to the gui_scripts group. [project.entry-points] is a collection of sub-tables, where each sub-table name is an entry point group and the key/value semantics match [project.scripts]. You must not create nested sub-tables inside entry point groups; keep them one level deep. Build back-ends must raise an error if metadata defines [project.entry-points.console_scripts] or [project.entry-points.gui_scripts], because those would be ambiguous with [project.scripts] and [project.gui-scripts].

[project.scripts]
example-cli = "example_package.cli:main"

The dynamic key and its rules

The dynamic key is an array of strings naming keys that were intentionally left unspecified so another tool can provide them. This distinguishes deliberate omission from accidental omission. The rules are strict: name must never appear in dynamic, and a build back-end must honor statically specified metadata. If a key is both specified statically and listed in dynamic, the back-end may only append entries to its value; it must not remove, reorder or modify the static entries. For tables such as optional-dependencies or entry-points this means the back-end may add new keys or append to existing list values, but cannot change what you wrote statically. A back-end should raise an error if a key is listed in dynamic that it cannot extend.

[project]
name = "example-package"
dynamic = ["version"]

The [tool] table and naming rules

The [tool] table is where any tool related to your Python project, not only build tools, stores configuration, always in a sub-table such as [tool.flit] for the flit tool. To prevent different projects from colliding on the same sub-table, the specification allocates names: a project may use the tool.$NAME sub-table if and only if it owns the entry for $NAME on PyPI. In practice this means you should not invent a [tool.requests] section for your own settings; pick a name you control or one whose documented schema you are following.

[tool.black]
line-length = 88

How declared metadata relates to repeatable installation

The dependencies declared in [project] define what should be installed, but pip's repeatable-install practices control which exact artifacts get installed. Pinning with == in a requirements file (generated by pip freeze, which records installed distributions and their versions, including transitive dependencies) protects against bugs in newly released versions. Hash-checking mode adds --hash entries so pip verifies downloaded artifacts, guarding against a compromised index or a package changing without a version bump; pip-compile needs --generate-hashes to emit hashes and pip needs --require-hashes to enforce them. A wheelhouse built with pip wheel bundles compiled dependencies for offline installation, but such archives are OS- and architecture-specific and not portable across machines. Note the division of labor: pyproject.toml declares abstract dependencies; the requirements file and wheelhouse pin the concrete, verified resolution.

wheel_dir="$(mktemp -d)"
python -m pip wheel -r requirements.txt --wheel-dir "$wheel_dir"
python -m pip install --force-reinstall --no-index --no-deps "$wheel_dir"/*.whl

Things to check

  • [build-system] contains a requires list and no invalid keys
  • [project] name is set statically and does not appear in dynamic
  • Every dependencies string is a valid dependency specifier
  • license is a valid SPDX expression and no License:: classifiers are used
  • readme uses either a string or a table with exactly one of file/text and a content-type
  • No [project.entry-points.console_scripts] or [project.entry-points.gui_scripts] tables exist
  • Entry point groups under [project.entry-points] are one level deep
  • Tool configuration lives under [tool.$NAME] for a name you own on PyPI

The specification is formal and does not replace the user guide for writing pyproject.toml. The setuptools [build-system] example is illustrative; the backend choice depends on the project. The tool.$NAME ownership rule is tied to PyPI name registration. Repeatable-install practices described here apply to pip and do not cover every package manager. A wheelhouse contains platform-specific compiled packages and is not portable across operating systems and architectures.

Sources

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