Automated Action f207cc3c64 Create RESTful API service with FastAPI and SQLite
- Set up project structure with FastAPI and dependency files
- Configure SQLAlchemy with SQLite database
- Implement user authentication using JWT tokens
- Create comprehensive API routes for user management
- Add health check endpoint for application monitoring
- Set up Alembic for database migrations
- Add detailed documentation in README.md
2025-06-16 14:56:03 +00:00

44 lines
1.0 KiB
Python

from typing import List, Optional
from pydantic_settings import BaseSettings
from pydantic import validator
import os
class Settings(BaseSettings):
# API information
PROJECT_NAME: str = "RESTAPIService"
DESCRIPTION: str = "A RESTful API service built with FastAPI and SQLite"
VERSION: str = "0.1.0"
API_V1_PREFIX: str = "/api/v1"
# Security
SECRET_KEY: str = os.environ.get("SECRET_KEY", "supersecretkey")
ALGORITHM: str = "HS256"
ACCESS_TOKEN_EXPIRE_MINUTES: int = 30
# CORS
ALLOWED_HOSTS: List[str] = ["*"]
# Database
SQLALCHEMY_DATABASE_URI: Optional[str] = None
@validator("SQLALCHEMY_DATABASE_URI", pre=True)
def assemble_db_uri(cls, v, values):
if v:
return v
from pathlib import Path
# Set up database directory
db_dir = Path("/app") / "storage" / "db"
db_dir.mkdir(parents=True, exist_ok=True)
return f"sqlite:////{db_dir}/db.sqlite"
class Config:
env_file = ".env"
case_sensitive = True
settings = Settings()