First commit
This commit is contained in:
69
api/app/config.py
Normal file
69
api/app/config.py
Normal file
@@ -0,0 +1,69 @@
|
||||
"""
|
||||
Configuration de l'API Cheque Scanner
|
||||
"""
|
||||
|
||||
import os
|
||||
from pydantic_settings import BaseSettings
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Charger les variables d'environnement depuis le fichier .env
|
||||
load_dotenv()
|
||||
|
||||
class Settings(BaseSettings):
|
||||
"""Configuration de l'application"""
|
||||
|
||||
# Informations de base
|
||||
APP_NAME: str = "Cheque Scanner API"
|
||||
API_VERSION: str = "v1"
|
||||
API_PREFIX: str = f"/api/{API_VERSION}"
|
||||
DEBUG: bool = os.getenv("DEBUG", "False").lower() == "true"
|
||||
|
||||
# Sécurité
|
||||
API_KEY: str = os.getenv("API_KEY", "your-secret-api-key")
|
||||
|
||||
# Configuration du serveur
|
||||
HOST: str = os.getenv("HOST", "0.0.0.0")
|
||||
PORT: int = int(os.getenv("PORT", "8000"))
|
||||
|
||||
# Configuration Redis
|
||||
REDIS_HOST: str = os.getenv("REDIS_HOST", "redis")
|
||||
REDIS_PORT: int = int(os.getenv("REDIS_PORT", "6379"))
|
||||
REDIS_DB: int = int(os.getenv("REDIS_DB", "0"))
|
||||
REDIS_URL: str = os.getenv("REDIS_URL", f"redis://{REDIS_HOST}:{REDIS_PORT}/{REDIS_DB}")
|
||||
|
||||
# Configuration des files d'attente
|
||||
QUEUE_NAME: str = os.getenv("QUEUE_NAME", "cheque_processing")
|
||||
HIGH_PRIORITY_QUEUE_NAME: str = os.getenv("HIGH_PRIORITY_QUEUE_NAME", "cheque_processing_high")
|
||||
|
||||
# Configuration du stockage
|
||||
UPLOAD_FOLDER: str = os.getenv("UPLOAD_FOLDER", "/app/data/uploads")
|
||||
RESULT_FOLDER: str = os.getenv("RESULT_FOLDER", "/app/data/results")
|
||||
TEMP_FOLDER: str = os.getenv("TEMP_FOLDER", "/app/data/tmp")
|
||||
MAX_CONTENT_LENGTH: int = int(os.getenv("MAX_CONTENT_LENGTH", "16777216")) # 16MB
|
||||
ALLOWED_EXTENSIONS: set = {"png", "jpg", "jpeg", "gif", "tiff", "pdf"}
|
||||
|
||||
# Configuration du traitement d'image
|
||||
DEFAULT_OCR_LANGUAGE: str = os.getenv("DEFAULT_OCR_LANGUAGE", "eng")
|
||||
ALTERNATIVE_OCR_LANGUAGE: str = os.getenv("ALTERNATIVE_OCR_LANGUAGE", "fra")
|
||||
TESSERACT_DATA_PATH: str = os.getenv("TESSERACT_DATA_PATH", "/usr/share/tesseract-ocr/4.00/tessdata")
|
||||
|
||||
# Délais et timeouts
|
||||
JOB_TIMEOUT: int = int(os.getenv("JOB_TIMEOUT", "300")) # 5 minutes
|
||||
RESULT_TTL: int = int(os.getenv("RESULT_TTL", "86400")) # 24 heures
|
||||
|
||||
# Limites
|
||||
MAX_WORKERS: int = int(os.getenv("MAX_WORKERS", "3"))
|
||||
RATE_LIMIT: int = int(os.getenv("RATE_LIMIT", "100")) # requêtes par heure
|
||||
|
||||
class Config:
|
||||
env_file = ".env"
|
||||
case_sensitive = True
|
||||
|
||||
|
||||
# Instance de configuration globale
|
||||
settings = Settings()
|
||||
|
||||
# Créer les dossiers nécessaires s'ils n'existent pas
|
||||
os.makedirs(settings.UPLOAD_FOLDER, exist_ok=True)
|
||||
os.makedirs(settings.RESULT_FOLDER, exist_ok=True)
|
||||
os.makedirs(settings.TEMP_FOLDER, exist_ok=True)
|
||||
Reference in New Issue
Block a user