Package: converge
Contents1What is it?2Getting started2.1Easy to use2.2Install2.3Supported environment variables3Supported settings files4Guidelines5Overriding settings5.1Example6Overriding partial settings7(Slightly) Advanced usage7.1Using SETTINGS_DIR1What is it?If you are a Python developer who likes to keep application configuration in simple Python modules and that your app have some default settings and production/dev/test setting files,convergecan help you merge settings and start the application with desired settings based on environment variables.2Getting started2.1Easy to use./settings/default_settings.py-------------------SERVER_PORT=8000DOMAIN='example.com'ADMIN_EMAIL='admin@example.com'./settings/dev_settings.py---------------SERVER_PORT=9000importsettingsprint(settings.SERVER_PORT)# 9000print(settings.DOMAIN)# example.comprint(settings.get('VAR_THAT_DOESNT_EXIST'))# None2.2Installpipinstallconverge2.3Supported environment variables_All directives are optional._APP_MODEValid values aredev (default)teststagingbetaprodBased onmodeappropriate settings module would be used (if available)SETTINGS_DIRDefaults to “settings”.If your settings files are in different directory, use SETTINGS_DIR to point converge to correct path.NoteRemember to drop __init__.py in settings directory.GIT_SETTINGS_REPOFetching application settings from a git repository is supported too. If such configuration is specified, git repository is cloned intoSETTINGS_DIR.GIT_SETTINGS_SUBDIRIn case you
- use same git repository to host configurations of more than one applications and
- say settings files are in different subdirectoriesExamplemy-git-repo/
  |
  |- myapp1
  |    |
  |    |- default_settings.py
  |    |- prod_settings.py
  |
  |
  |- myapp2export SETTINGS_DIR='appsettings'
export GIT_SETTINGS_REPO='git@github.com:shon/converge-test-settings.git'
export GIT_SETTINGS_SUBDIR='myapp1'In this case all *_settings.py files in myapp1/ would be copied to appsettings.Exampleexport APP_MODE='test'
export SETTINGS_DIR='settings'
export GIT_SETTINGS_REPO='git@github.com:shon/converge-test-settings.git'
export GIT_SETTINGS_SUBDIR='myapp1'3Supported settings filesDefaults: default_settings.pyModeproduction: prod_settings.pydevelopment: dev_settings.pytest: test_settings.pystaging: staging_settings.pybeta: beta_settings.pyDeployment specific: site_settings.py4GuidelinesSettings files are usual Python files that can contain valid python code however here are some guidelines for userUse module variables for global application wide configurationUse UPPERCASE while naming settings variablesFor values prefer basic python datatypes such as string, integer,
tupleseg.SERVER_PORT = 1234Avoid complex python operationsUse simple classes for config sectionsclassDB:HOST='db.example.com'PORT=1234Use simple string operations to avoid repetitionBASE_DOMAIN='example.com'API_URL='api.'+BASE_DOMAIN``5Overriding settingsDefining module veriables in site_settings.py5.1Exampledefault_settings.pySERVER_PORT = 9999site_settings.pySERVER_PORT = 88886Overriding partial settingsExample:default_settings.pyclassDB:HOST='db.example.com'PORT=1234site_settings.pyDB.PORT=11117(Slightly) Advanced usageIn case if you want to keep all settings.py files in a directory. UseSETTINGS_DIRenvironment variable.7.1Using SETTINGS_DIRexportAPP_MODE='prod'exportSETTINGS_DIR='settings/fat_server'This is useful when you have to deploy multiple instances of an app with different configs`-- settings/
     |
     |-- server1/
     |      |
     |      |--default_settings.py
     |      |--prod_settings.py
     |
     |-- server2/
     |      |--default_settings.py
     |      |--prod_settings.py
     |
     |