$ pip install django-environ
import environ
env = environ.Env(# set casting, default valueDEBUG=(bool, False))# reading .env fileenviron.Env.read_env()
# False if not in os.environDEBUG = env('DEBUG')
# Raises Django's ImproperlyConfigured exception if SECRET_KEY not in os.environSECRET_KEY = env('SECRET_KEY')
#!/usr/bin/env python
from os import environ
# Initialize variablesnum_of_vars = 50for i in range(1, num_of_vars):environ[f"_BENCHMARK_{i}"] = f"BENCHMARK VALUE {i}"
def stopwatch(repeat=1, autorun=True):"""Source: https://stackoverflow.com/a/68660080/5285732stopwatch decorator to calculate the total time of a function"""import timeitimport functools
def outer_func(func):@functools.wraps(func)def time_func(*args, **kwargs):t1 = timeit.default_timer()for _ in range(repeat):r = func(*args, **kwargs)t2 = timeit.default_timer()print(f"Function={func.__name__}, Time={t2 - t1}")return r
if autorun:try:time_func()except TypeError:raise Exception(f"{time_func.__name__}: autorun only works with no parameters, you may want to use @stopwatch(autorun=False)") from None
return time_func
if callable(repeat):func = repeatrepeat = 1return outer_func(func)
return outer_func
@stopwatch(repeat=10000)def using_environ():for item in environ:pass
@stopwatchdef using_dict(repeat=10000):env_vars_dict = dict(environ)for item in env_vars_dict:pass