Currently, it's already possible to determine whether an environment variable exists by using the native os.environ module. However, this requires an extra import and isn't quite as clean as the proposed addition to the environs package.
from os import environ
from environs import env
env.read_env()
if environ.get("ENV_VAR_INT"):
value: int = env.int("ENV_VAR_INT")
print(f"Exists! value == {value:,}")
else:
print(f"Doesn't exist!")
I'm proposing a wrapper around the aforementioned implementation that will eliminate the extra import and improve code readability.
from environs import env
env.read_env()
if env.exists("ENV_VAR_INT"):
value: int = env.int("ENV_VAR_INT")
print("Exists! value == {value:,}")
else:
print("Doesn't exist!")