17. Handy Commands

CLI recipes for environments, profiling, servers, containers, and quick API checks.

# Environment & deps
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip

# Quality toolchain
pytest -q
pytest -k "keyword" -q
ruff check . && ruff format .
mypy .

# Profiling CPU and visualizing
python -m cProfile -o prof.out app.py
python -m pip install snakeviz && snakeviz prof.out

# Simple servers & clients
python -m http.server 8000
uvicorn app:app --reload --port 8000

# SQLAlchemy migrations (Alembic)
alembic revision -m "add users"
alembic upgrade head
# Pre-commit hooks
python -m pip install pre-commit && pre-commit install

# Coverage
pytest --cov=your_package --cov-report=term-missing -q

# Docker build & compose
docker build -t app:dev .
docker compose up -d

# Quick API check with idempotency key
curl -i -H "Idempotency-Key: test-123" -H "Content-Type: application/json" \
  -d '{"name":"x","price":1.0}' http://localhost:8000/items