Files
skeleton-api/app/core/config.py
T

53 lines
1.4 KiB
Python

"""Application configuration.
Settings are read from environment variables first, then from a `.env` file.
Environment variables always take precedence over the file.
"""
from functools import lru_cache
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
extra="ignore",
case_sensitive=False,
)
# General
app_name: str = "FastAPI Skeleton"
debug: bool = False
# Security / JWT
secret_key: str = "change-me-please-use-a-long-random-string"
algorithm: str = "HS256"
access_token_expire_minutes: int = 15
refresh_token_expire_days: int = 7
# Database — single URL drives SQLite or Postgres.
# SQLite: sqlite+aiosqlite:///./app.db
# Postgres: postgresql+asyncpg://user:pass@host:5432/dbname
database_url: str = "sqlite+aiosqlite:///./app.db"
auto_create_tables: bool = True
# Web / cookies (the HTMX UI stores the access token in an httpOnly cookie)
cookie_name: str = "access_token"
cookie_secure: bool = False
# CORS
cors_origins: list[str] = ["*"]
# Bootstrap superuser (used by scripts/seed.py)
first_superuser_email: str = "admin@example.com"
first_superuser_password: str = "changethis"
@lru_cache
def get_settings() -> Settings:
return Settings()
settings = get_settings()