from functools import lru_cache from pydantic_settings import BaseSettings, SettingsConfigDict from pydantic import Field class Settings(BaseSettings): # ----------------------- # App # ----------------------- app_name: str = "MyApp" env: str = "PROD" debug: bool = False # ----------------------- # Database / Cache # ----------------------- database_url: str = Field(..., description="Async database DSN") redis_url: str # ----------------------- # Security / API Keys # ----------------------- openai_api_key: str stripe_api_key: str model_config = SettingsConfigDict( env_file=".env", env_file_encoding="utf-8", case_sensitive=False, ) @lru_cache def get_settings() -> Settings: """ 避免多次实例化 Settings(FastAPI 官方推荐) """ return Settings() settings = get_settings() # ----------------------- # Global constants # ----------------------- BASE_CURRENCY = "EUR"