Skip to content

Instantly share code, notes, and snippets.

@billryan
Created February 24, 2018 06:16
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 billryan/c65efe252a3e99fe34c6f41b5618e4fe to your computer and use it in GitHub Desktop.
Save billryan/c65efe252a3e99fe34c6f41b5618e4fe to your computer and use it in GitHub Desktop.
Python config class for different environment
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from os import getenv
basedir = os.path.abspath(os.path.dirname(__file__))
class Config(object):
DEBUG = False
TESTING = False
MYSQL_HOST = getenv('MYSQL_HOST', '192.168.1.1')
# get attribute
def __getitem__(self, key):
return self.__getattribute__(key)
class ProductionConfig(Config):
DEBUG = False
MSSQL_HOST = getenv('MSSQL_HOST', '192.168.8.8')
class DevelopmentConfig(Config):
DEBUG = True
MSSQL_HOST = getenv('MSSQL_HOST', '192.168.4.4')
class TestingConfig(Config):
TESTING = True
mapping = {
'development': DevelopmentConfig,
'testing': TestingConfig,
'production': ProductionConfig,
'default': DevelopmentConfig
}
APP_ENV = os.environ.get('APP_ENV', 'default').lower()
config = mapping[APP_ENV]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment