env_cast¶
-
privex.helpers.common.env_cast(env_key: str, cast: callable, env_default=None)[source]¶ Obtains an environment variable
env_key, if it’s empty or not set,env_defaultwill be returned. Otherwise, it will be converted into a type of your choice using the callablecastparameterExample:
>>> os.environ['HELLO'] = '1.234' >>> env_cast('HELLO', Decimal, Decimal('0')) Decimal('1.234')
- Parameters
cast (callable) – A function to cast the user’s env data such as
intstrorDecimaletc.env_key (str) – Environment var to attempt to load
env_default (any) – Fallback value if the env var is empty / not set (Default: None)