Debian Codegraph @

docs/examples/onboarding/fastapi/state.py

raw
1 from litestar import Litestar, get
2 from litestar.datastructures import State
3 from litestar.di import Provide
4
5
6 class ArqRedis:
7 """Stand-in for an ``arq`` Redis client."""
8
9
10 async def get_arq_redis(state: State) -> ArqRedis:
11 return state.arq_redis
12
13
14 @get("/", dependencies={"arq_redis": Provide(get_arq_redis)})
15 async def handler(arq_redis: ArqRedis) -> dict[str, str]:
16 return {"type": type(arq_redis).__name__}
17
18
19 app = Litestar(
20 route_handlers=[handler],
21 state=State({"arq_redis": ArqRedis()}),
22 )