Best-practice workflow and guardrails for Python backend work (APIs/services, data access, background jobs, CLIs). Use when Codex is writing or refactoring Python application code, setting up Python tooling, improving performance, adding tests, or making packaging/lint/type-check decisions (uv, Ruff, mypy, pytest), including data tooling choices (prefer polars) and secure config patterns (.env).
Apply these rules when producing or modifying Python backend code. Optimize for correctness, performance, and maintainability while keeping changes small and reversible.
uv for dependency management and virtual environments (.venv) when appropriate for the repo.ipykernel/ipywidgets into the local .venv when needed, but do not add them to runtime requirements.pathlib.Path over raw string paths for file operations (unless the repo standard differs).enumerate() over manual counters.Any; if unavoidable, isolate it at the boundary (e.g., parsing/IO) and convert to typed structures quickly.pydantic models if the repo already uses them) for structured data.except:.logger.exception(...) when handling unexpected failures.polars over pandas for new dataframe work unless the repo standardizes on pandas.polars DataFrame, do not redundantly print both schema and row counts unless explicitly requested..env for local dev..env is excluded via .gitignore when relevant.