Course contentsShow
← Python
Lesson 525 of 1,0608. Professional Tooling and PackagingFree lesson

Configuring Project Metadata Declaratively

Populate the project table with essential information like version, authors, and license to ensure compatibility with modern packaging tools.

In this lesson, you will learn how to shift your project’s identity from imperative scripts to a clean, declarative configuration using the [project] table in your pyproject.toml file.

Moving Beyond setup.py

In the past, packaging metadata was often defined inside a setup.py file using executable Python code. This was dangerous and unpredictable because the installer had to run your script just to find out your project's name or version. Today, we define this metadata declaratively. By listing your project details as static data in pyproject.toml, you provide modern build tools with a standardized "source of truth" that is fast, secure, and easy to parse.

The [project] Table

The [project] table is the standard place to tell the world who you are and what your project does. Instead of writing logic to parse files, you simply state your configuration. Here is a typical example:

[project]
name = "data-processor"
version = "1.2.0"
description = "A high-performance library for cleaning JSON datasets."
authors = [
    { name = "Jane Developer", email = "jane@example.com" }
]
license = { text = "MIT" }
requires-python = ">=3.10"
dependencies = [
    "requests>=2.28.0",
    "pydantic>=2.0.0",
]

Why Declarative Matters

When you use a declarative approach:

  1. Tool Compatibility: Build backends (like Hatch, Flit, or Setuptools) can read your metadata without executing arbitrary code, preventing security risks.
  2. Readability: Anyone opening your project can instantly see the version, requirements, and license at the top of the file without hunting through Python classes.
  3. Consistency: Because this format follows PEP 621, your metadata remains compatible across different build tools and package repositories (like PyPI).

By keeping this data static, you ensure that your project’s identity is predictable, regardless of which environment or tool is being used to package your code.

Key Takeaway: Defining your project metadata in the [project] table of pyproject.toml ensures that your package’s identity is static, secure, and universally understood by modern Python build tools.