Skip to main content

Creating a setup.py file

Historically setup.py was the imperative entry point setuptools executed during pip install. Today declarative pyproject.toml is preferred, yet millions of OSS packages still expose setup.py for editable installs (pip install -e .) hooks and compatibility with older tooling.


📚 Prerequisites

  • Virtual environments and importing your own modules (Chapter 2).

🎯 What you'll learn

  • Read a legacy setup.py without panic.
  • Know when PEP 517 build isolation still executes it.
  • Migrate mentally toward declarative configs in the next lesson.

Minimal historical pattern

from setuptools import setup, find_packages

setup(
name="tinytool",
version="0.1.0",
packages=find_packages(where="src"),
package_dir={"": "src"},
python_requires=">=3.10",
)

Anything beyond trivial metadata often moves to setup.cfg or pyproject.toml to prevent arbitrary code execution during metadata-only operations.


Why teams still glance at setup.py

  • Custom command classes (setup.py upload_docs antiques).
  • Dynamic version generation reading git tags (discouraged for new repos—prefer setuptools-scm with declarative configs).

💡 Key takeaways

  • Treat setup.py as legacy surface area you may need to read, even if new work lands in PEP 621 metadata files.

➡️ Next steps

Build distributable artifacts with setuptools in Packaging your Python project with setuptools.