6. Packaging & Tooling

Standardize builds and tooling in pyproject.toml; pin deps and automate quality checks.

Question: What tools are essential for a modern Python project?

Answer: A modern Python project relies on tools for dependency management, code formatting, linting, and type checking, typically configured in pyproject.toml.

Explanation:

  • Dependency Management: venv creates isolated environments. pip installs packages. A requirements.txt (from pip-tools) or a poetry.lock file pins dependency versions for reproducible builds.

  • Code Quality: black is the standard for formatting. ruff is an extremely fast linter and formatter that can replace flake8 and isort.

  • Type Checking: mypy is the standard for static type checking.

  • Testing: pytest is the de-facto standard for testing.

Additions: Centralize config in pyproject.toml and use pre-commit hooks to enforce formatting/linting before commits.

Question: What belongs in pyproject.toml (PEP 621), and how do you pin deps?

Answer: Declare project metadata and tool configs in pyproject.toml; use pip-tools to compile locked requirements.txt; install dev code with pip install -e ..

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

[project]
name = "myapp"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = ["fastapi", "uvicorn"]