todoapi-0h1oi4/app/core/config.py
Automated Action 7fa5fb0213 Setup complete Todo API with FastAPI and SQLite
- Create Todo model and schemas
- Set up API endpoints for CRUD operations
- Configure SQLAlchemy for database access
- Set up Alembic for database migrations
- Add Ruff for code linting
- Update README with project documentation
2025-05-27 06:32:35 +00:00

49 lines
1.3 KiB
Python

"""
Configuration settings for the application.
"""
from pathlib import Path
from typing import List, Union
from pydantic import AnyHttpUrl, BaseSettings, validator
class Settings(BaseSettings):
"""
Application settings.
"""
PROJECT_NAME: str = "Todo API"
VERSION: str = "0.1.0"
API_V1_STR: str = "/api/v1"
# BACKEND_CORS_ORIGINS is a comma-separated list of origins
# e.g: "http://localhost:8000,http://localhost:3000"
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
@validator("BACKEND_CORS_ORIGINS", pre=True)
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> List[str]:
"""
Parse CORS origins from string or list.
"""
if isinstance(v, str) and not v.startswith("["):
return [i.strip() for i in v.split(",")]
if isinstance(v, (list, str)):
return v
raise ValueError(v)
# Database configuration
DB_DIR: Path = Path("/app") / "storage" / "db"
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
class Config:
"""
Config class for Settings.
"""
case_sensitive = True
# Create settings instance
settings = Settings()
# Ensure DB directory exists
settings.DB_DIR.mkdir(parents=True, exist_ok=True)