📦 Junior Python Track 36 • Capstone Package Publishing

36. Packaging & Distribution

Master modern Python packaging & library distribution: understand pyproject.toml (PEP 621), package directory layouts (src-layout), Semantic Versioning (SemVer), building Wheel (.whl) artifacts, local editable installs (pip install -e .), and publishing to PyPI with twine.

📄

pyproject.toml & PEP 621

The modern declarative configuration file replacing legacy `setup.py`. Defines build system requirements, project metadata, authors, dependencies, and entry-point CLI scripts.

  • `[build-system]`: Specifies build backend (`setuptools`, `hatchling`).
  • `[project]`: Standard metadata fields (version, dependencies).
  • `[project.scripts]`: Register CLI terminal commands.
🏷️

Semantic Versioning (SemVer)

Standardized 3-part versioning format (`MAJOR.MINOR.PATCH`) to clearly signal breaking changes, backwards-compatible additions, and patch bug fixes.

  • MAJOR (`1.0.0` → `2.0.0`): Incompatible API breaking changes.
  • MINOR (`1.0.0` → `1.1.0`): Backwards-compatible new features.
  • PATCH (`1.0.0` → `1.0.1`): Backwards-compatible bug fixes.
📦

Wheels & PyPI Upload

Build distribution packages into pre-compiled binary Wheel (`.whl`) files and source archives (`.tar.gz`) for publication to the Python Package Index (PyPI).

  • `python -m build`: Generate `.whl` and `.tar.gz` in `./dist/`.
  • `pip install -e .`: Install package in local editable mode.
  • `twine upload dist/*`: Securely publish release artifacts to PyPI.
📦 Packaging, Distribution & Dependency Studio

pyproject.toml, SemVer, Building & PyPI Publishing

PEP 621 | PEP 517 | Wheel

📄 pyproject.toml & PEP 621

Single source of truth for build backend (`setuptools`, `hatchling`, `flit`), project metadata, and dependencies.

🏷️ Semantic Versioning

Follow `MAJOR.MINOR.PATCH` rules to communicate breaking changes, new features, and backwards-compatible fixes.

🛠️ Building & PyPI Upload

Build binary Wheels (`.whl`) & source archives (`.tar.gz`) via `python -m build` and publish with `twine upload`.

✅ Ready for Packaging Execution
=== EXECUTION RESULT ===

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

[project]
name = "teachcloud-sdk"
version = "1.4.2"
description = "TeachCloud Enterprise Python SDK"
readme = "README.md"
requires-python = ">=3.10"
license = { text = "MIT" }
authors = [
    { name = "TeachCloud Engineering", email = "dev@teachcloud.dev" }
]
dependencies = [
    "requests>=2.31.0",
    "pydantic>=2.5.0"
]
# ==============================================================================
# PEP 621 PYPROJECT.TOML CONFIGURATION GENERATOR
# ==============================================================================
def generate_pyproject_toml(name: str, version: str) -> str:
    return f"""[build-system]
requires = ["setuptools>=61.0.0", "wheel"]
build-backend = "setuptools.build_meta"

[project]
name = "{name}"
version = "{version}"
requires-python = ">=3.10"
dependencies = ["requests>=2.31.0", "pydantic>=2.5.0"]
"""
💎 Junior Track 36 Master Reference

36. Packaging & Distribution Tooling Comparison

📊 Modern Python Packaging Ecosystem

Tool Category Primary Role PEP Compliance
setuptools Build Backend Standard Python build system backend PEP 517 / PEP 621
hatchling / flit Modern Build Backend Lightweight PEP 621 compliant backends PEP 517 / PEP 621
build CLI Builder Generates `.whl` and `.tar.gz` packages PEP 517 Frontend
twine PyPI Uploader Securely uploads artifacts to PyPI via HTTPS PyPI API Specification

⭐ Rate Track 36: Packaging & Distribution (1 to 5 Stars)

Your rating is stored directly in the database. Average: 5.0 / 5 (1 rating)

★ ★ ★ ★ ★
← 35. Concurrency & Async Masterclass 🎓 Junior Hub (36 Modules Complete!) ⭐ Practice 100+ Interview Questions →