mirror of
https://github.com/fastapi/fastapi.git
synced 2026-01-06 04:57:58 -05:00
* ➕ Add pydantic-settings to all extras * 📝 Update docs for Pydantic settings * 📝 Update Settings source examples to use Pydantic v2, and add a Pydantic v1 version * ✅ Add tests for settings with Pydantic v1 and v2 * 🔥 Remove solved TODO comment * ♻️ Update conditional OpenAPI to use new Pydantic v2 settings
22 lines
419 B
Python
22 lines
419 B
Python
from fastapi import FastAPI
|
|
from pydantic_settings import BaseSettings
|
|
|
|
|
|
class Settings(BaseSettings):
|
|
app_name: str = "Awesome API"
|
|
admin_email: str
|
|
items_per_user: int = 50
|
|
|
|
|
|
settings = Settings()
|
|
app = FastAPI()
|
|
|
|
|
|
@app.get("/info")
|
|
async def info():
|
|
return {
|
|
"app_name": settings.app_name,
|
|
"admin_email": settings.admin_email,
|
|
"items_per_user": settings.items_per_user,
|
|
}
|