Declaring a Project License in pyproject.toml: SPDX String, Legacy Table, Classifier Conflict, and license-files Globs
PEP 639 replaced the legacy license table with a single SPDX expression string and introduced license-files for glob-based license distribution, while deprecating License:: classifiers.
On this page
The short answer
Use the license key as a plain SPDX expression string and pair it with license-files for glob patterns. Avoid the deprecated table form and License:: classifiers simultaneously.
Context and Recommendation: SPDX Expression String as the Modern License Declaration
The pyproject.toml specification originally allowed the license key to hold a structured table with file or text subkeys. PEP 639, approved in December 2024, redefined the license key to accept a single string containing an SPDX expression. This change solves a concrete problem: build tools and metadata consumers previously had to handle two different shapes for the same field, and the table form could not express compound expressions like "MIT OR Apache-2.0" without ambiguity. The string form maps directly to the License-Expression core metadata field, giving downstream consumers a machine-readable, unambiguous value.
The specification states that the expression applies to all distribution files generated from the pyproject.toml. If the license differs per distribution artifact, the key should be listed as dynamic or omitted entirely.
Practical tip
If your build backend has not adopted PEP 639 yet, the legacy table form may still work without warning, but migrating early prevents breakage when the backend updates.
The New license Key as a String Value
Under the current specification, the license key has TOML type string and corresponds to the License-Expression core metadata field. The value is an SPDX expression string such as "MIT", "Apache-2.0", or "BSD-3-Clause AND MIT". The specification does not enumerate which SPDX expressions are valid or define a grammar for parsing them beyond treating the value as an opaque string. Build back-ends pass this string through to the metadata without validating it against the SPDX license list.
The key may be listed as dynamic in the dynamic array, meaning a build backend provides the value at build time rather than reading it from the static TOML file.
The Legacy license Table with file and text Keys
Before PEP 639, the license key accepted a TOML table with two mutually exclusive subkeys: file (a path relative to pyproject.toml pointing to a UTF-8 encoded license file) and text (the license string inline). Tools were required to raise an error if both keys were present. PEP 639 deprecated this table form in favor of the string value. The specification notes that build tools not yet updated to PEP 639 may still accept the legacy table form without warning, so projects targeting older toolchains should verify their backend's behavior.
The corresponding core metadata field for the legacy table was License (not License-Expression), which is a different field entirely.
Conflict with License:: Classifiers
Trove classifiers in the License :: family are deprecated by PEP 639. The specification states that tools MAY issue a warning when a License :: classifier is present. More importantly, build tools MAY raise an error if both the license string value (which translates to License-Expression) and a License :: classifier are used simultaneously. This means projects should choose one mechanism: either the SPDX string in the license key, or a License :: classifier, but not both. The recommended path is the SPDX string, since classifiers are deprecated.
The license-files Key and Glob Pattern Requirements
The license-files key has TOML type array of strings and corresponds to the License-File core metadata field. Each string in the array MUST contain a valid glob pattern relative to the directory containing pyproject.toml. Tools MUST assume that matched file content is valid UTF-8 encoded text and SHOULD validate this assumption, raising an error if the content is not valid UTF-8.
The key is independent of the license key: license declares the expression, while license-files declares which files to include in the distribution archive. They complement each other without overlap.
Build Tool Obligations for license-files
The specification imposes several MUST rules on build tools regarding license-files. Tools MUST include all files matched by a listed pattern in all distribution archives. Tools MUST list each matched file path under a License-File field in the core metadata. If license-files is present and set to an empty array, tools MUST NOT include any license files and MUST NOT raise an error; this is an explicit suppression. If the key is absent entirely, tools MAY use their own logic to discover appropriate files or choose not to include any.
Concrete Illustration: A Project Using SPDX String and license-files Together
The following fragment shows a minimal pyproject.toml declaring license as an SPDX expression and license-files as a glob pattern. The license key communicates the legal terms as a machine-readable expression, while license-files ensures the actual text files are bundled into the distribution archive and listed in metadata. The two keys serve different purposes and do not conflict.
In this example, the glob pattern "LICENSE*" would match files like LICENSE, LICENSE.txt, or LICENSE-MIT at the project root. The build backend would include each matched file in the wheel and sdist, and emit a License-File metadata line for each path.
[project]
name = "example-package"
version = "1.0.0"
license = "MIT"
license-files = ["LICENSE*", "NOTICE"]Applicability Limits and Edge Cases
The specification does not define which SPDX expressions are valid or how to parse them beyond the string value. The license key may be listed as dynamic, but the source does not describe how to combine a dynamic license value with license-files patterns. No guidance is provided for projects whose license differs per distribution file; the only documented escape is to list license as dynamic or omit it. Build tools that have not adopted PEP 639 may still accept the legacy table form without warning, creating a silent compatibility gap.
Things to check
- The license key with a string value maps to License-Expression metadata, not License metadata
- The legacy table form with both file and text keys must raise an error per specification
- License :: classifiers are deprecated and may cause a build error when combined with the SPDX string
- license-files strings must be valid glob patterns relative to the pyproject.toml directory
- An empty license-files array suppresses inclusion without error
- license-files content is assumed UTF-8 and tools SHOULD validate this
Where this applies
Only the pyproject.toml specification source is directly relevant to this topic; the second provided source (pip repeatable installs) covers dependency pinning and hash checking, not license declaration. The specification does not define SPDX expression grammar or dynamic license interaction with license-files.