Last active
August 29, 2015 14:02
-
-
Save etscrivner/26ffb57238c3a88534db to your computer and use it in GitHub Desktop.
Sample interface for reading configuration files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
# Configuration variable names as constants | |
APP_NAME = 'MY_APP_NAME' | |
APP_AWS_KEY = 'MY_APP_AWS_KEY' | |
APP_AWS_SECRET_KEY = 'MY_APP_AWS_SECRET_KEY' | |
class Config(object): | |
def __init__(self, config=None): | |
"""Initialize config with mapping. | |
:param config: (Defaults to os.environ) A dict-like config object. | |
:type config: dict | |
""" | |
self.config = config if config else os.environ | |
def get(self, key, default=None): | |
return self.config.get(key, default) | |
def get_bool(self, key, default=False): | |
return self.config.get(key, str(default)).lower() in ('true', 't', '1') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment