setuptools

Setuptools is Python’s original and most established build backend, providing tools for building, distributing, and installing Python packages. It serves as the foundation for much of Python’s packaging ecosystem and supports a wide range of packaging use cases.

ℹ️
For many years, setuptools was the de facto standard for building Python packages. However, in recent years, language-level support was introduced for other packaging tools (e.g. Poetry and Hatch) , and setuptools-based workflows have become less popular.

Core Features

Build System

  • Package Creation: Builds both source distributions (sdists) and wheel distributions
  • Extension Module Support: Handles compilation of C extensions and Cython code
  • Entry Points: Manages console scripts and plugin registration
  • Resource Management: Handles package data files and non-code resources
  • Command Customization: Supports custom build steps and commands

Configuration Options

ℹ️
In the past, setuptools projects required a setup.py script to be present in the project root. However, this is no longer the case. setuptools configurations can be defined in pyproject.toml.

Setuptools can be configured through pyproject.toml or the legacy setup.py file:

# Modern configuration (pyproject.toml)
[build-system]
requires = ["setuptools>=61.0"]
build-backend = "setuptools.build_meta"

[project]
name = "example"
version = "0.1.0"
description = "Example package"
requires-python = ">=3.8"
dependencies = ["requests>=2.25.0"]
# Legacy configuration (setup.py)
from setuptools import setup

setup(
    name="example",
    version="0.1.0",
    description="Example package",
    python_requires=">=3.8",
    install_requires=["requests>=2.25.0"],
)

Pros

  • Mature and stable: Well-established with decades of development
  • Universal support: Works with all Python versions and platforms
  • Extensive documentation: Comprehensive guidance available
  • Rich feature set: Handles complex packaging scenarios
  • PEP 621 support: Compatible with modern Python packaging standards

Cons

  • Complex legacy API: Historical design choices can be confusing
  • No built-in dependency locking: Requires additional tools for lockfiles
  • Slower development cycle: Less frequent updates than newer tools
  • Steeper learning curve: More configuration options create complexity

Learn More

Last updated on

Please submit corrections and feedback...