Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions cre.py
Original file line number Diff line number Diff line change
@@ -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)