config.py•1.15 kB
"""
Configuration settings for the Unsplash API application.
This module provides a centralized place for all configuration settings,
including environment variables, API settings, and other constants.
"""
import os
from pydantic import BaseModel
from typing import Optional
class Settings(BaseModel):
"""
Application settings loaded from environment variables.
Attributes:
PROJECT_NAME: The name of the project.
UNSPLASH_CLIENT_ID: The Unsplash API client ID.
DEBUG: Whether the application is in debug mode.
"""
PROJECT_NAME: str = "Unsplash API"
UNSPLASH_CLIENT_ID: Optional[str] = None
DEBUG: bool = False
def get_settings() -> Settings:
"""
Load settings from environment variables.
Returns:
Settings object with values loaded from environment variables.
"""
return Settings(
PROJECT_NAME=os.environ.get("PROJECT_NAME", "Unsplash API"),
UNSPLASH_CLIENT_ID=os.environ.get("UNSPLASH_CLIENT_ID"),
DEBUG=os.environ.get("DEBUG", "").lower() in ("true", "1", "t"),
)
# Create a global settings instance
settings = get_settings()