Combining Static and Dynamic Metadata in pyproject.toml
In pyproject.toml, static metadata keys are declared directly in the file, while dynamic keys are listed in the project.dynamic array so a build backend can supply their values at build time. A backend must honour statically specified keys that are not listed in dynamic, and it must raise an error if name appears in dynamic. When a key is specified both statically and in dynamic (PEP 808), the backend may only append entries and must not modify or remove existing ones.
On this page
Key idea
The [project] table in pyproject.toml supports two metadata modes. Static keys such as name, description, and readme are written directly in the file; the build backend must honour them unchanged. Dynamic keys are declared in the project.dynamic array, signalling that an external tool will supply the value during the build. The key name must always be static and must never appear in dynamic. The key version is required but may be either static or dynamic. When a key is listed in dynamic and not specified statically, the backend provides its value entirely. When a key is specified both statically and in dynamic (PEP 808 hybrid mode), the backend may only append new entries to the existing value; it must not remove, reorder, or modify the statically specified entries. This design lets teams pin identifiers and descriptions in version control while generating version strings from Git tags or adding optional dependencies in CI pipelines.
How Static and Dynamic Keys Interact
The [project] table in pyproject.toml defines package metadata. Keys written directly in the table are static; the build backend reads them and must honour them without modification. Keys whose names appear in the project.dynamic array are dynamic; the backend is responsible for supplying their values at build time. The specification states that a backend MUST honour statically-specified metadata, meaning metadata that did not list the key in dynamic.
The key name is the only key that must always be static. A backend MUST raise an error if name is listed in dynamic. The key version is required but may be specified either statically or listed in dynamic. All other keys are optional and may be static, dynamic, or omitted entirely.
PEP 808 (approved May 2026) introduced a hybrid mode: a key can be specified both statically and listed in dynamic. In that case the backend MAY only append entries to the value and MUST NOT remove, reorder, or modify any statically specified entries. For tables such as optional-dependencies or entry-points, the backend MAY add new keys and MAY append to list values of existing keys.
[build-system]
requires = ["setuptools>=61.0", "setuptools-scm>=8.0"]
build-backend = "setuptools.build_meta"
[project]
name = "my-package"
description = "A sample package"
readme = "README.md"
requires-python = ">=3.10"
license = "MIT"
dynamic = ["version"]
[tool.setuptools_scm]
fallback_version = "0.0.0.dev0"Inspecting Static and Dynamic Keys with Python
The following example uses tomllib (available from Python 3.11) to parse a pyproject.toml file and report which keys are static and which are dynamic. It reads the [project] table, separates keys that appear in the dynamic list from those that do not, and prints each category. This makes the distinction concrete and verifiable without invoking a build backend.
Note: tomllib requires Python 3.11 or later. For earlier versions, use the third-party tomli package with the same API.
The output confirms that name, description, readme, requires-python, and license are static (the backend must honour them unchanged), while version is dynamic (the backend or an external tool must supply it). If version were also written as a key in [project] while still listed in dynamic, the PEP 808 append-only rule would apply.
import tomllib
with open("pyproject.toml", "rb") as f:
data = tomllib.load(f)
project = data["project"]
dynamic_keys = set(project.get("dynamic", []))
static_keys = [k for k in project if k != "dynamic" and k not in dynamic_keys]
print("Static keys (backend must honour):", static_keys)
print("Dynamic keys (backend supplies):", sorted(dynamic_keys))
# Simulate PEP 808: a key both static and dynamic
if "version" in project and "version" in dynamic_keys:
print(f"version is both static ({project['version']!r}) and dynamic -> append-only")
else:
print("version is purely dynamic; backend provides the value")Trade-offs and Failure Modes
A common mistake is listing name in dynamic. The specification requires a backend to raise an error in this case, so the build will fail immediately. Another mistake is omitting version from both the static keys and the dynamic list; since version is required, the backend must raise an error.
Not every build backend supports every dynamic key. For example, setuptools supports version via setuptools_scm or a file path, but a backend that does not support extending a particular key should raise an error when that key is listed in dynamic. Always verify that your chosen backend supports the keys you declare as dynamic.
The hybrid mode (static plus dynamic) is useful when you want a baseline value that CI can augment. For instance, you might list a core set of dependencies statically and let a CI plugin append environment-specific extras. The backend can add new entries but cannot remove or reorder the ones you wrote.
# This configuration is INVALID: name must not be in dynamic.
# A compliant backend will raise an error.
[project]
name = "my-package"
dynamic = ["name", "version"] # ERROR: name cannot be dynamicApplicability Limits
The dynamic mechanism only applies to keys defined in PEP 621. Tool-specific configuration under [tool] is not part of the metadata specification and is not subject to the static/dynamic distinction.
PEP 808 append-only behaviour is a recent addition (May 2026). Older backends may not implement it, so a key listed both statically and in dynamic might be rejected or handled differently. Check your backend's changelog before relying on hybrid mode.
The import-names and import-namespaces keys (PEP 794, October 2025) support dynamic calculation, but only if the backend explicitly implements it. A backend SHOULD raise an error if a key is listed in dynamic and the backend does not support providing or extending that key. For PEP 808 hybrid mode specifically, if a key is both statically specified and listed in dynamic, the backend must support the append-only operation or raise an error.
# Verify your backend supports the dynamic keys you declare.
# This snippet checks whether setuptools_scm is installed and
# can produce a version string from the current Git state.
import subprocess, sys
result = subprocess.run(
[sys.executable, "-c", "import setuptools_scm; print(setuptools_scm.get_version())"],
capture_output=True, text=True
)
if result.returncode == 0:
print("Dynamic version resolved:", result.stdout.strip())
else:
print("setuptools_scm failed:", result.stderr.strip())Applicability
- Build backend supports PEP 621 (e.g. setuptools >= 61.0 or hatchling).
- The key version is either specified statically or listed in project.dynamic, not omitted entirely.
- The key name is never listed in project.dynamic; a backend must raise an error if it is.
- Statically specified keys not listed in dynamic are honoured unchanged by the backend.
- When a key appears both statically and in dynamic (PEP 808), the backend may only append entries, not modify or remove existing ones.
Where this applies
Not every build backend supports every dynamic key. PEP 808 hybrid mode (static plus dynamic with append-only semantics) was approved in May 2026 and may not be implemented by older backends. The key name must never be listed in dynamic. A backend SHOULD raise an error if a key is listed in dynamic and the backend does not support providing or extending that key.