Automated Action 4bbc49f04d Create a FastAPI REST API service with SQLite database
- Set up project structure
- Configure SQLite database with SQLAlchemy
- Create item model and schema
- Set up Alembic for database migrations
- Implement CRUD operations for items
- Add health check endpoint
- Add API documentation
- Configure Ruff for linting
- Update README with project information
2025-05-23 09:14:12 +00:00

35 lines
992 B
Python

from pathlib import Path
from typing import List, Union
from pydantic import AnyHttpUrl, validator
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
API_V1_STR: str = "/api/v1"
PROJECT_NAME: str = "REST API Service"
# CORS configuration
BACKEND_CORS_ORIGINS: List[AnyHttpUrl] = []
@validator("BACKEND_CORS_ORIGINS", pre=True)
def assemble_cors_origins(cls, v: Union[str, List[str]]) -> Union[List[str], str]:
if isinstance(v, str) and not v.startswith("["):
return [i.strip() for i in v.split(",")]
elif isinstance(v, (list, str)):
return v
raise ValueError(v)
# Database
DB_DIR: Path = Path("/app") / "storage" / "db"
SQLALCHEMY_DATABASE_URL: str = f"sqlite:///{DB_DIR}/db.sqlite"
class Config:
case_sensitive = True
env_file = ".env"
settings = Settings()
# Ensure the database directory exists
settings.DB_DIR.mkdir(parents=True, exist_ok=True)