Skip to content
forked from shon/converge

Ultra simple settings management for Python (only) applications

License

Notifications You must be signed in to change notification settings

rohitkrai03/converge

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pip install converge
echo 'DEV' > .app_mode
echo 'SERVER_PORT = 8000' > default_settings.py
echo 'SERVER_PORT = 9000' > dev_settings.py
echo 'SERVER_PORT = 80' > prod_settings.py

Python

from converge import settings
print(settings.SERVER_PORT)

settings.get('VAR_THAT_DOESNT_EXIST')  # returns None

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 logic

  • 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``
  • 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

Create a file .app_mode This file would have just one line specifying settings (and hence app’s) mode.

Valid values are

  • PROD
  • DEV
  • TEST
  • STAGING

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

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

About

Ultra simple settings management for Python (only) applications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 100.0%