Skip to content

Instantly share code, notes, and snippets.

@cantoniazzi
Created March 29, 2018 19:53
Show Gist options
  • Save cantoniazzi/1a2511303fdf3e30f1eb544ac6b0607e to your computer and use it in GitHub Desktop.
Save cantoniazzi/1a2511303fdf3e30f1eb544ac6b0607e to your computer and use it in GitHub Desktop.
A python gist example to settings with environments. You must create a file called settings.cfg at the root of your project and put their keys in this file. It will not be committed to the repository.
settings.cfg
[s3-dev]
s3_key: ---
secret_key: ---
[s3-hlg]
s3_key: ---
secret_key: ---
[s3-prod]
s3_key: ---
secret_key: ---
import os
import configparser
class Settings():
def __init__(self):
self.environment = os.environ['ENVIRONMENT'] # dev / hlh / prod
self.BASE_DIR = os.path.abspath(os.path.dirname(__file__))
self.__config = configparser.ConfigParser()
self.__config.read(os.path.join(self.BASE_DIR, 'settings.cfg'))
def s3_credentials(self):
return {
's3_key': self.__config.get('s3-{}'.format(self.environment), 'key'),
'secret_key': self.__config.get('s3-{}'.format(self.environment), 'secret_key')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment