The pyproject.toml Fields I Fill In Before Every Release
Python packaging used to involve setup.py, setup.cfg and a lot of folklore. Today most of the metadata lives in a single [project] table in pyproject.toml, defined by PEP 621 and documented in the Python Packaging User Guide. It is easy to fill in the name and version and stop there. Here is the fuller set I check before each release, and why each one matters.
An illustrative starting point
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "example-tables"
version = "1.2.0"
description = "Read and write small fixed-width tables."
readme = "README.md"
requires-python = ">=3.9"
license = "MIT"
authors = [{ name = "Maintainer B" }]
dependencies = ["typing-extensions>=4.0"]
classifiers = [
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
]
[project.urls]
Source = "https://example.org/example-tables"
Changelog = "https://example.org/example-tables/CHANGELOG.md"
The build backend here is only an example; setuptools, flit-core, pdm-backend and others read the same [project] table. The URLs are placeholders.
The fields that affect users directly
name is what people type in pip install. PyPI normalises names, so underscores, hyphens and dots are treated as equivalent, and case does not matter. Pick one spelling and use it consistently.
version must follow PEP 440, which is not identical to semantic versioning. Prereleases are written like 1.3.0rc1 rather than 1.3.0-rc.1. If you prefer to derive the version from Git tags, declare it under dynamic and let your build backend fill it in.
requires-python is enforced by pip, so a wrong value either blocks people who could use your package or lets people install a release that will not run.
dependencies should list what the package needs at runtime, with lower bounds where you depend on a feature. Avoid strict upper pins in a library; they cause resolution conflicts for applications that combine many packages.
The fields people skip
readme becomes the project description on PyPI. Without it, the package page is nearly empty. license has been evolving: newer packaging metadata accepts an SPDX expression such as "MIT" or "Apache-2.0", while older tooling used a table or classifiers. Check what your build backend supports before you publish. [project.urls] gives users a way to find the source and changelog, which matters when they are deciding whether to trust an upgrade.
Checks before uploading
- Build both a source distribution and a wheel, then inspect the wheel's contents.
- Run
twine check dist/*to catch README rendering problems. - Install the wheel in a fresh virtual environment and import the package.
- Consider TestPyPI for the first release of a new project.
None of this is glamorous, but metadata is the first thing installers and people see. For definitions of terms like wheel and sdist, see the glossary.