Created
February 24, 2018 06:16
-
-
Save billryan/c65efe252a3e99fe34c6f41b5618e4fe to your computer and use it in GitHub Desktop.
Python config class for different environment
This file contains hidden or 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
#!/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