Skip to main content

Packaging your Python project with setuptools

setup.py basics introduced the imperative story; modern maintainers declare metadata in pyproject.toml and let setuptools act as the build backend (PEP 517).


📚 Prerequisites

  • Comfortable running pip install inside virtual environments.

🎯 What you'll learn

  • Author [build-system] + [project] tables consumable by python -m build.
  • Produce wheels (*.whl) suitable for caches and CDNs.

Declarative project metadata

[build-system]
requires = ["setuptools>=61", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "tinytool"
version = "0.1.0"
description = "Example utility package"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"requests>=2.31",
]

[project.scripts]
tiny = "tinytool.cli:main"

Build artifacts:

python -m pip install build
python -m build

Outputs land in dist/ as source archives and wheels.


Editable installs

During active development:

pip install -e ".[dev]"

Extras ([dev]) declare optional tooling like pytest pinned separately from runtime deps.


💡 Key takeaways

  • Wheels beat pure setup.py sdist flows for repeatable installs—they bundle pre-built metadata installers understand.

➡️ Next steps

Containerize dependencies with Docker basics for Python.