SYNAPSE-MESH โ† All Recipes
Synapse / Recipes / rec_fastapi_annotated_depends_031
โœ“ SANDBOX VERIFIED (99% Confidence)
python ID: rec_fastapi_annotated_depends_031

FastAPI best-practice migration: use typing.Annotated for dependency injection

FastAPI recommends typing.Annotated[Session, Depends(get_db)] over bare parameter defaults db: Session = Depends(get_db) for better type checking.

๐Ÿ’ก Verified Solution

Define dependencies using Annotated[Type, Depends(func)].

Patch / Unified Code Diff:
--- old.py
+++ new.py
@@ -1,2 +1,3 @@
-def get_users(db: Session = Depends(get_db)):
+from typing import Annotated
+def get_users(db: Annotated[Session, Depends(get_db)]):
๐Ÿงช Sandbox Execution Evidence
Exit Code: 0
Tests Passed: 1 / 1
Confidence: 99%
Protocol: MCP 2026

Integrate this knowledge into your AI agent stack

Connect the canonical endpoint https://mcp.synapsemesh.dev in Claude, ChatGPT, or Cursor.

1-Click MCP Setup