Skip to content

Instantly share code, notes, and snippets.

@etscrivner
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save etscrivner/26ffb57238c3a88534db to your computer and use it in GitHub Desktop.
Save etscrivner/26ffb57238c3a88534db to your computer and use it in GitHub Desktop.
Sample interface for reading configuration files
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