33 lines
836 B
Python
33 lines
836 B
Python
|
|
import os
|
|
from functools import lru_cache
|
|
|
|
from pydantic import Field
|
|
from pydantic_settings import BaseSettings, SettingsConfigDict
|
|
|
|
|
|
class _BaseConfig(BaseSettings):
|
|
model_config = SettingsConfigDict(
|
|
env_file=".env", extra="ignore", nested_model_default_partial_update=True
|
|
)
|
|
|
|
|
|
class _AppSettings(_BaseConfig):
|
|
environment: str = Field(default=os.getenv("ENVIRONMENT"))
|
|
|
|
|
|
class _DbSettings(_BaseConfig):
|
|
username: str = Field(default=os.getenv("PG_USER"), alias="PG_USER")
|
|
password: str = Field(default=os.getenv("PG_PASSWORD"), alias="PG_PASSWORD")
|
|
db_name: str = Field(default=os.getenv("PG_DB_NAME"), alias="PG_DB_NAME")
|
|
|
|
|
|
class _Settings(_BaseConfig):
|
|
app: _AppSettings = _AppSettings()
|
|
db: _DbSettings = _DbSettings()
|
|
|
|
|
|
@lru_cache
|
|
def get_settings() -> _Settings:
|
|
return _Settings()
|