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.
ℹ️
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
- Setuptools Documentation
- PEP 621 Support
- Packaging Python Projects Guide
- Setuptools with pyproject.toml Example
- Setuptools with setup.py Example
Also Mentioned In
- How Python's RFC Process Paved the Way for uv, Ruff, and Ty
- Why isn't Python packaging part of core development?
- The uv build backend is now stable
- build
- pyproject.toml
- What is a Python package?
- What is PEP 517/518 compatability?
- What is PEP 621 compatability?
- What is PEP 660?
- What is PyPA (Python Packaging Authority)?
- Why are there so many Python packaging tools?
Last updated on