Packaging & Dependency Management
Master modern Python project packaging. Build declarative pyproject.toml specifications (PEP 621), virtual environment isolation (venv), build backends, dev dependency groups, and Semantic Versioning.
Legacy Unpinned Global Installs vs Declarative pyproject.toml
Do not install packages into global system Python or rely on unpinned loose text files. Use virtual environments (`venv`) and declarative `pyproject.toml` dependencies.
# ❌ Pollutes global system Python site-packages!
pip install fastapi sqlalchemy
# requirements.txt (unpinned, breaks builds)
fastapi
sqlalchemy
# ✅ Isolated venv & explicit SemVer bounds
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
📦 Packaging & Dependency Management Components
Declarative single-file project metadata, build backend configuration, and tool settings.
Isolated Python execution environment preventing version collisions between projects.
Standardized build engines generating distribution wheels (.whl) and source archives.
Strict MAJOR.MINOR.PATCH versioning guaranteeing API compatibility across releases.
💻 Production Blueprint: Standard pyproject.toml Configuration
Declarative build system separating main application runtime packages from development & testing dependencies.
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "cloud-app"
version = "1.0.0"
requires-python = ">=3.11"
dependencies = [
"fastapi>=0.110.0,<1.0.0",
"sqlalchemy[asyncio]>=2.0.28",
"pydantic>=2.6.0",
]
[project.optional-dependencies]
dev = [
"pytest>=8.0.0",
"mypy>=1.8.0",
"ruff>=0.3.0",
]