Skip to main content

Section 9.1 Python Gold Standards

Note ID: 202605080001 | Tags: python

Subsection 9.1.1 Python Rule of Thumb

Subsection 9.1.2 Gold Standard Python Template

# src/example.py
"""
Script descriptiion

Author:
Date:
"""
# imports and typing

__future__ import annotations           # Type hinting

__all__ = ["public_function"]            # Explicitly declare public API

# -----------------------------------------------------------------------------------------------------------
# 0️⃣ Typing helpers / protocols / constants (if needed)
# -----------------------------------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------------------------------
# 1️⃣ Core definitions
# -----------------------------------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------------------------------
# 2️⃣ Public API (functions users are meant to call)
# -----------------------------------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------------------------------
# 3️⃣ Private helpers
# -----------------------------------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------------------------------
# 4️⃣ Smoke tests / example usage
# -----------------------------------------------------------------------------------------------------------

# -----------------------------------------------------------------------------------------------------------
# 5️⃣ Entry point
# -----------------------------------------------------------------------------------------------------------

Subsection 9.1.3 Fundamental Features

Note 9.1.4. "Big functions" to bundle logic..

Use large functions to bundle related logic together.

Note 9.1.5. Type Annotations Everywhere (within reason).

πŸ”‘ Key Habits to Remember: