Python FastAPI service
Async FastAPI service with SQLAlchemy 2.0, Alembic migrations, strict typing, and money stored in minor units.
Composed from the python-fastapi rules pack. Same file from the CLI: aibysitter init --packs python-fastapi --format claude
Written for this site, CC0, scored by this linter, not tested against any agent.
- File
- CLAUDE.md, 41 lines
- Format
- CLAUDE.md
- Save as
CLAUDE.md- Category
- Python
- Tags
- License
- CC0 1.0, public domain. No attribution needed.
Download CLAUDE.md Lint a copy
Aibysitter lint score
100 / 100 — A
Ruleset v4
No deductions.
Badge
Markdown for a README:
[](https://aibysitting.net/Gallery/python-fastapi)
CLAUDE.md
# Python FastAPI service Python 3.12, FastAPI, SQLAlchemy 2.0 (async), PostgreSQL, Alembic. Dependencies and commands run through uv. ## Commands - Install: `uv sync` - Run: `uv run fastapi dev src/<app>/main.py` - Test: `uv run pytest` - Lint: `uv run ruff check .` - Format: `uv run ruff format .` - Type check: `uv run mypy src` - New migration: `uv run alembic revision --autogenerate -m "<summary>"`, then read the generated file before committing it. ## Layout - `src/<app>/api/`: routers, one module per resource. - `src/<app>/services/`: business logic. No FastAPI imports. - `src/<app>/db/`: models, session, repositories. - `tests/` mirrors `src/<app>/`. ## API - Request and response bodies are Pydantic v2 models in `src/<app>/schemas/`. ORM models are never returned from a route. - Routes declare `response_model` and an explicit `status_code`. - `HTTPException` is raised only in routers. Services raise domain errors from `<app>.errors`, and `api/errors.py` maps them to status codes. - Database sessions come from the `get_session` dependency. Services do not open sessions. ## Money - Amounts are integers in minor units (cents). No floats for money. - Every amount is stored with an ISO 4217 currency code next to it. ## Code style - Every function signature has type hints. `mypy --strict` passes for `src/`. - Ruff rules live in `pyproject.toml`. A `# noqa` comment always names the rule code. - Timestamps use `datetime.now(tz=UTC)`. Naive datetimes are a bug. ## Tests - pytest with `pytest-asyncio`. Async tests use the `async_client` fixture from `tests/conftest.py`. - Database tests run against the Postgres container started by `docker compose up -d db`. - A bug fix starts with a failing test that reproduces the bug. ## Done - `ruff check`, `ruff format --check`, `mypy`, and `pytest` all pass.
# Python FastAPI servicePython 3.12, FastAPI, SQLAlchemy 2.0 (async), PostgreSQL, Alembic. Dependencies and commands run through uv.## Commands- Install: `uv sync`- Run: `uv run fastapi dev src/<app>/main.py`- Test: `uv run pytest`- Lint: `uv run ruff check .`- Format: `uv run ruff format .`- Type check: `uv run mypy src`- New migration: `uv run alembic revision --autogenerate -m "<summary>"`, then read the generated file before committing it.## Layout- `src/<app>/api/`: routers, one module per resource.- `src/<app>/services/`: business logic. No FastAPI imports.- `src/<app>/db/`: models, session, repositories.- `tests/` mirrors `src/<app>/`.## API- Request and response bodies are Pydantic v2 models in `src/<app>/schemas/`. ORM models are never returned from a route.- Routes declare `response_model` and an explicit `status_code`.- `HTTPException` is raised only in routers. Services raise domain errors from `<app>.errors`, and `api/errors.py` maps them to status codes.- Database sessions come from the `get_session` dependency. Services do not open sessions.## Money- Amounts are integers in minor units (cents). No floats for money.- Every amount is stored with an ISO 4217 currency code next to it.## Code style- Every function signature has type hints. `mypy --strict` passes for `src/`.- Ruff rules live in `pyproject.toml`. A `# noqa` comment always names the rule code.- Timestamps use `datetime.now(tz=UTC)`. Naive datetimes are a bug.## Tests- pytest with `pytest-asyncio`. Async tests use the `async_client` fixture from `tests/conftest.py`.- Database tests run against the Postgres container started by `docker compose up -d db`.- A bug fix starts with a failing test that reproduces the bug.## Done- `ruff check`, `ruff format --check`, `mypy`, and `pytest` all pass.