Warning

🚧 Work in Progress: This page is currently under construction. Content may be incomplete or subject to change. To contribute, see the contribution guide.

Python Standards


Formatting

  • Formatter: Black — no style debates, Black decides
  • Import sorter: isort
  • Linter: ruff
  • Line length: 88 characters (Black default)
# Install tools
pip install black isort ruff
 
# Format
black .
isort .
 
# Lint
ruff check .

Python project structure

my-project/
├── src/
│   └── my_module/
│       ├── __init__.py
│       └── main.py
├── tests/
│   └── test_main.py
├── requirements.txt
├── pyproject.toml
└── README.md

Docstrings

def calculate_nav(asset_value: float, liabilities: float) -> float:
    """Calculate the Net Asset Value of an asset.
 
    Args:
        asset_value: Gross asset value in BRL.
        liabilities: Total associated liabilities in BRL.
 
    Returns:
        Calculated NAV in BRL.
 
    Raises:
        ValueError: If asset_value is negative.
    """
    if asset_value < 0:
        raise ValueError("asset_value cannot be negative")
    return asset_value - liabilities

Secrets and configuration

# ✅ CORRECT — via environment variable
import os
api_key = os.environ["MY_API_KEY"]
 
# ❌ WRONG — never hardcoded
api_key = "sk-1234abcd..."