docs_src/settings/app02_an_py310/main.py
raw| 1 | from functools import lru_cache |
| 2 | from typing import Annotated |
| 3 | |
| 4 | from fastapi import Depends, FastAPI |
| 5 | |
| 6 | from .config import Settings |
| 7 | |
| 8 | app = FastAPI() |
| 9 | |
| 10 | |
| 11 | @lru_cache |
| 12 | def get_settings(): |
| 13 | return Settings() |
| 14 | |
| 15 | |
| 16 | @app.get("/info") |
| 17 | async def info(settings: Annotated[Settings, Depends(get_settings)]): |
| 18 | return { |
| 19 | "app_name": settings.app_name, |
| 20 | "admin_email": settings.admin_email, |
| 21 | "items_per_user": settings.items_per_user, |
| 22 | } |