Skip to content

Instantly share code, notes, and snippets.

@Ichinga-Samuel
Last active September 25, 2022 03:25
Show Gist options
  • Save Ichinga-Samuel/ec98c14a4fc3b657d6b3e7fd10c50f34 to your computer and use it in GitHub Desktop.
Save Ichinga-Samuel/ec98c14a4fc3b657d6b3e7fd10c50f34 to your computer and use it in GitHub Desktop.
from os import environ
from dotenv import load_dotenv, dotenv_values
class Config:
def __init__(self):
load_dotenv()
# setup non secret config variables here
self.public = "public"
[setattr(self, key, value) for key, value in dotenv_values('config.env').items()]
def __getattr__(self, item):
attr = environ.get(item.upper())
setattr(self, item, attr) if attr is not None else ... # this is not really necessary
return attr
env = Config()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment