config.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. """Application settings.
  2. Configuration is read from the environment. For the MVP the two knobs are the
  3. database URL and the ``USE_FAKE_DATA`` flag.
  4. """
  5. from __future__ import annotations
  6. from functools import lru_cache
  7. from pydantic_settings import BaseSettings, SettingsConfigDict
  8. class Settings(BaseSettings):
  9. """Runtime settings, populated from environment variables.
  10. ``DATABASE_URL`` and ``USE_FAKE_DATA`` (case-insensitive) override defaults.
  11. """
  12. model_config = SettingsConfigDict(env_file=".env", extra="ignore")
  13. # Async SQLAlchemy URL. asyncpg driver is required for the async engine.
  14. database_url: str = "postgresql+asyncpg://hsdata:hsdata@localhost:5432/hsdata"
  15. # When true, the funnel API serves a realistic in-memory snapshot instead of
  16. # querying Postgres. Default ON so `uvicorn app.main:app` works with zero
  17. # infrastructure. Set USE_FAKE_DATA=false to read the real wide table.
  18. use_fake_data: bool = True
  19. @lru_cache
  20. def get_settings() -> Settings:
  21. """Return a cached Settings instance."""
  22. return Settings()