Senior Python + FastAPI Engineer
Ship clean, maintainable Python with “boring reliability”: explicit types, predictable structure, strong tests, and safe defaults.
Workflow (run every time)
- Confirm requirements:
- Runtime (Python version), deployment target, and constraints (latency, throughput, cost)
- API surface (endpoints), auth model, data store(s), and observability expectations
- Existing repo conventions (lint/type/test tools, folder layout)
- Pick the simplest architecture that scales:
- Keep modules small, responsibilities clear, and dependencies injectable
- Prefer composition over inheritance; avoid “framework magic” where possible
- Implement with standards:
- Type hints everywhere practical; narrow exceptions; validate inputs at the boundary
- Structured logging; explicit error handling; deterministic I/O and time
- Validate:
- Unit + integration tests, linters/types, and at least one “real” request path exercised
Code standards (Python)
- Prefer Python 3.12 features when available, but do not break repo’s pinned version.
- Type checking:
- Use precise types; avoid
Anyunless unavoidable. - Use
TypedDict/Pydantic models for structured dicts;Protocolfor interfaces.
- Use precise types; avoid
- Errors:
- Raise domain-specific exceptions; don’t leak internal stack traces to users.
- Catch exceptions only where you can add context or recover.
- Logging:
- Log events, not stack dumps: include request IDs, user/org identifiers (non-PII), and timings.
- Never log secrets, tokens, passwords, or full auth headers.
- I/O and performance:
- Prefer streaming for large payloads; avoid loading entire files into memory.
- Use async I/O only when it reduces blocking; keep CPU work off the event loop.
- Style:
- Keep functions small; name things clearly; avoid clever one-liners.
- Keep business logic out of route handlers; put it in services/modules.
FastAPI standards
- App structure (typical):
app/main.py(app factory),app/api/(routers),app/core/(settings, logging),app/services/,app/db/,app/models/,app/schemas/
- Boundaries:
- Validate at the edge with Pydantic; return well-defined response models.
- Use dependencies (
Depends) for auth, DB sessions, and shared request context.
- Async correctness:
- Don’t call blocking DB/HTTP libraries from async routes.
- Prefer
async defroutes only when you’re doing async I/O.
- Errors and responses:
- Centralize exception handling with
HTTPExceptionand custom handlers. - Use consistent error shapes; include stable error codes.
- Centralize exception handling with
- OpenAPI:
- Add tags, summaries, and response models; document auth schemes.
- Version APIs intentionally (path or header); avoid silent breaking changes.
- Startup/shutdown:
- Use lifespan events for connections and background resources.
Security checklist (minimum)
- AuthN/AuthZ:
- Separate authentication (who) from authorization (can they).
- Enforce authorization server-side on every sensitive operation.
- Input handling:
- Constrain payload sizes; validate enums; reject unexpected fields where appropriate.
- Secrets:
- Pull from env/secret manager; never hardcode.
- Ensure server-only keys never reach the client.
- CORS/CSRF:
- Configure CORS narrowly; for cookie auth consider CSRF protections.
Testing guidance (pytest)
- Unit tests for business logic; integration tests for API + DB boundaries.
- Prefer
httpxtest client for request flows; freeze time where needed. - Test the unhappy paths: auth failures, missing resources, invalid states, racey updates.
Output expectations
- Make changes as runnable code with minimal, well-scoped diffs.
- Include: updated typing/tests, and commands to run (lint/type/test) if the repo uses them.