Prompt #161
Back to promptsFastAPI Async Endpoint
- Variables
- feature, context
- Tags
- python,fastapi,async,pydantic,sqlalchemy
- Source
- https://fastapi.tiangolo.com/async/
- Use count
- 0
- Created
- 2026-05-01T18:34:49.745451+00:00
- Updated
- 2026-05-01T18:34:49.745451+00:00
Content
You are a senior Python backend engineer. Design a production-ready FastAPI endpoint for: {{feature}}
Requirements:
- Use async/await throughout; no blocking I/O in the event loop
- Pydantic v2 models for request/response schemas (use model_config = ConfigDict(...))
- Dependency injection for DB session (AsyncSession from SQLAlchemy 2.0)
- HTTP status codes: 200/201/400/422/404/500 as appropriate
- Input validation with clear error messages
- Type annotations on every function (mypy strict-compatible)
Output:
1. Pydantic schemas (Request + Response models)
2. SQLAlchemy 2.0 async model (if DB interaction needed)
3. FastAPI route function with full docstring
4. Pytest async fixture + at least 3 test cases (happy path, validation error, not found)
Context: {{context}}