Code style¶
SAE Books is a Python codebase. We use the standard tools.
Tooling¶
- Formatter:
ruff format(Black-equivalent, 100 cols) - Linter:
ruff check - Types:
mypyin strict mode for new modules; legacy modules opted-in incrementally - Tests:
pytestwithpytest-asyncio
Run lint and type checks before opening a PR:
Imports¶
at the top of every file. Then standard library, then third-party,
then saebooks.*. ruff handles the sort.
Naming¶
snake_casefor functions, variables, modules.PascalCasefor classes.SCREAMING_SNAKE_CASEfor module-level constants.- Async functions get a
async_prefix only when there is a same-named sync sibling and the disambiguation matters. Otherwise justdefvsasync def.
Docstrings¶
Module and public-API docstrings are required. They should explain why the code exists, not what each line does. Don't waste lines on restating the function signature.
Errors¶
- Validate at boundaries (HTTP, external APIs). Trust internal calls.
- Raise
HTTPExceptionfrom FastAPI handlers; raise typed exceptions from service layers and let the handler translate. - Don't catch and re-log; let exceptions propagate to the global handler unless you can do something useful with them.
Tests¶
See Testing.