tofu-api/tofu_api/common/config/config.py

33 lines
835 B
Python

import yaml
from flask import Config as BaseConfig
from .defaults import DefaultConfig
class Config(BaseConfig):
"""
Custom config class for the Flask application.
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Set app-specific default values
self.from_object(DefaultConfig)
def from_yaml(self, filename: str, *, silent: bool = False) -> bool:
"""
Update config from a YAML file.
"""
return self.from_file(filename, load=yaml.safe_load, silent=silent)
# Properties for type safe access to config values
@property
def sqlalchemy_database_uri(self) -> str:
return self.get('SQLALCHEMY_DATABASE_URI')
@property
def sqlalchemy_echo(self) -> bool:
return bool(self.get('SQLALCHEMY_ECHO'))