from pathlib import Path from typing import Optional from pydantic_settings import BaseSettings class Settings(BaseSettings): # Base settings PROJECT_NAME: str = "QuickRestAPI" PROJECT_DESCRIPTION: str = "A simple REST API built with FastAPI and SQLite" PROJECT_VERSION: str = "0.1.0" # Server settings HOST: str = "0.0.0.0" PORT: int = 8000 DEBUG: bool = True # Database settings DB_DIR: Path = Path("/app") / "storage" / "db" SQLALCHEMY_DATABASE_URL: Optional[str] = None def __init__(self, **kwargs): super().__init__(**kwargs) # Ensure DB directory exists self.DB_DIR.mkdir(parents=True, exist_ok=True) # Set database URL if not provided if self.SQLALCHEMY_DATABASE_URL is None: self.SQLALCHEMY_DATABASE_URL = f"sqlite:///{self.DB_DIR}/db.sqlite" class Config: env_file = ".env" env_file_encoding = "utf-8" case_sensitive = True settings = Settings()