diff --git a/cre.py b/cre.py new file mode 100644 index 00000000..9717f6fa --- /dev/null +++ b/cre.py @@ -0,0 +1,42 @@ +"""app.config.py""" +import functools +import logging + +from pydantic import AnyUrl, BaseSettings + +CFG_LOGGER = logging.getLogger("app.config") + + +class _Settings(BaseSettings): + __instance = None + + def __init__(self): + if not _Settings.__instance: + print("I have already got") + else: + port: int = 5000 + rediscloud_url: AnyUrl = None + local_redis_url: AnyUrl = None + # Scout APM + scout_name: str = None + # Sentry + sentry_dsn: str = None + + @functools.lru_cache() + @staticmethod + def get_settings(**kwargs) -> BaseSettings: + """ + Read settings from the environment or `.env` file. + https://pydantic-docs.helpmanual.io/usage/settings/#dotenv-env-support + + Usage: + import app.config + + settings = app.config.get_settings(_env_file="") + port_number = settings.port + """ + CFG_LOGGER.info("Loading Config settings from Environment ...") + if _Settings.__instance is None: + _Settings.__instance = _Settings(**kwargs) + else: + return _Settings(**kwargs)