Coder Social home page Coder Social logo

converge's Introduction

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, converge can help you merge settings and load desired application settings.

default_settings.py
-------------------
SERVER_PORT = 8000
DOMAIN = 'example.com'
ADMIN_EMAIL = '[email protected]'

dev_settings.py
---------------
SERVER_PORT = 9000
from converge import settings
print(settings.SERVER_PORT)  # 9000
print(settings.DOMAIN)  # example.com
print(settings.get('VAR_THAT_DOESNT_EXIST'))  # None
pip install converge

.convergerc file helps converge choose application mode and in turn load correct settings file.

_All directives are optional._

APP_MODE

Valid values are

  • prod
  • dev
  • test
  • staging

Based on mode appropriate settings module would be used (if available)

SETTINGS_DIR

If your settings files are in different directory, use SETTINGS_DIR to point converge to correct path.

Note

Remember to drop __init__.py in settings directory.

GIT_SETTINGS_REPO

Fetching application settings from a git repository is supported too. If such configuration is specified, git repository is cloned into SETTINGS_DIR.

GIT_SETTINGS_SUBDIR

In case you - use same git repository to host configurations of more than one applications and - say settings files are in different subdirectories

Example

my-git-repo/
  |
  |- myapp1
  |    |
  |    |- default_settings.py
  |    |- prod_settings.py
  |
  |
  |- myapp2
cat .convergerc

SETTINGS_DIR = 'appsettings'
GIT_SETTINGS_REPO = '[email protected]:shon/converge-test-settings.git'
GIT_SETTINGS_SUBDIR = 'myapp1'

In this case all *_settings.py files in myapp1/ would be copied to appsettings.

Example

.convergerc
-----------

APP_MODE = 'test'
SETTINGS_DIR = 'settings'
GIT_SETTINGS_REPO = '[email protected]:shon/converge-test-settings.git'
GIT_SETTINGS_SUBDIR = 'myapp1'
  • Defaults: default_settings.py
  • Mode
    • production: prod_settings.py
    • development: dev_settings.py
    • test: test_settings.py
    • staging: staging_settings.py
  • Deployment specific: site_settings.py

Settings files are usual Python files that can contain valid python code however here are some guidelines for user

  • Use module variables for global application wide configuration

  • Use UPPERCASE while naming settings variables

  • For values prefer basic python datatypes usch as string, integer, tuples

  • eg. SERVER_PORT = 1234

  • Avoid complex python operations

  • Use simple classes for config sections
    class DB:
        HOST = 'db.example.com'
        PORT = 1234
  • Use simple string operations to avoid repeatation
    BASE_DOMAIN = 'example.com'
    API_URL = 'api.' + BASE_DOMAIN``

Defining module veriables in site_settings.py

default_settings.py

SERVER_PORT = 9999

site_settings.py

SERVER_PORT = 8888

Example:

default_settings.py

class DB:
    HOST = 'db.example.com'
    PORT = 1234

site_settings.py

DB.PORT = 1111

In case if you want to keep all settings.py files in a directory. Use SETTINGS_DIR directive in .convergerc file.

>> cat .convergerc

APP_MODE = 'prod'
SETTINGS_DIR = 'settings/fat_server'

This is useful when you have to deply multiple instances of an app with different configs

`-- settings/
     |
     |-- server1/
     |      |
     |      |--default_settings.py
     |      |--prod_settings.py
     |
     |-- server2/
     |      |--default_settings.py
     |      |--prod_settings.py
     |
     |

converge's People

Contributors

shon avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.