# FastAPI, Pydantic v2, Lifespan Events & Async Dependency Injection > Verified FastAPI reference covering Annotated[T, Depends(...)], lifespan context managers, Pydantic v2 ConfigDict, and async event-loop safety. ## Corpus Summary - Canonical Space URL: https://voxell.ai/p/fastapi-docs - Documents indexed: 4 (43 passages, 39.7 KB) - Citation Readiness (Aggarwal GEO): 52/100 (stat_density=0.00, self_contained=1.00) - Full machine-readable corpus bundle: https://voxell.ai/s/fastapi-docs/llms-full.txt ## Agent & MCP Integration (Zero API Key Required) Connect any MCP client or autonomous agent directly via Streamable HTTP: - Endpoint: `POST https://voxell.ai/s/fastapi-docs/mcp` - Tools: `search_verified_docs` (grounded passage search), `ask_cited_answer` (cited synthesis) ```bash curl -sS -X POST https://voxell.ai/s/fastapi-docs/mcp \ -H 'Content-Type: application/json' \ -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"search_verified_docs","arguments":{"query":"key facts and specifications","top_k":5}}}' ``` ## Document & Section Map - **official_ref_2_raw_githubusercontent_com_fa.md** (29 passages, 22.3 KB) - **official_ref_1_fastapi_fastapi.md** (12 passages, 16.4 KB) - Section: FastAPI - FastAPI - **fastapi-pydantic-v2-patterns.md** (1 passages, 423 B) - Section: Pydantic v2 Models in FastAPI - **fastapi-lifespan-and-dependencies.md** (1 passages, 629 B) - Section: FastAPI Lifespan Context Managers & Annotated Dependencies ## Verified Sample Citations (High Fact Density) - **[fastapi-pydantic-v2-patterns.md #0]**: # Pydantic v2 Models in FastAPI Use Pydantic v2 idioms exclusively: - `model_config = ConfigDict(from_attributes=True, extra='forbid')` instead of `class Config: orm_mode = True`. - `obj.model_dump()` / `obj.model_dump_json()` instead of `.dict()` / `.json()`. - `Model.model_validate(data)` instead of `Model.parse_obj(data)`. - `@field_validator('field')`... - **[fastapi-lifespan-and-dependencies.md #0]**: # FastAPI Lifespan Context Managers & Annotated Dependencies Initialize shared database pools and HTTP clients inside an `@asynccontextmanager async def lifespan(app: FastAPI): ... yield ...` passed to `FastAPI(lifespan=lifespan)`, replacing deprecated `@app.on_event('startup')` / `@app.on_event('shutdown')`. Declare reusable dependencies with `typing.Ann... - **[official_ref_1_fastapi_fastapi.md #5]**: │ │ │ Serving at: http://127.0.0.1:8000 │ │ │ │ API docs: http://127.0.0.1:8000/docs │ │ │ │ Running in development mode, for production use: │ │ │ │ fastapi run │ │ │ ╰──────────────────────────────────────────────────... - **[official_ref_1_fastapi_fastapi.md #4]**: ---> 100% Note : Make sure you put "fastapi[standard]" in quotes to ensure it works in all terminals. If you prefer to use pip , install fastapi[standard] inside a virtual environment. See the installation guide for the alternative steps. Example ¶ Create it ¶ Create a file main.py with: from fastapi import FastAPI app = FastAPI () @app . get ( "/" ) de... - **[official_ref_1_fastapi_fastapi.md #7]**: @app . get ( "/items/ {item_id} " ) def read_item ( item_id : int , q : str | None = None ): return { "item_id" : item_id , "q" : q } @app . put ( "/items/ {item_id} " ) def update_item ( item_id : int , item : Item ): return { "item_name" : item . name , "item_id" : item_id } The fastapi dev server should reload automatically. Interactive API docs upgrad... - **[official_ref_1_fastapi_fastapi.md #3]**: " [...] I'm using FastAPI a ton these days. [...] I'm actually planning to use it for all of my team's ML services at Microsoft . Some of them are getting integrated into the core Windows product and some Office products. " Kabir Khan - Microsoft (ref) " We adopted the FastAPI library to spawn a REST server that can be queried to obtain predictions . [for...