Ultra simple settings management for (only) Python apps
Project description
1 What 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, converge can help you merge settings and load desired application settings.
2 Getting started
2.1 Easy to use
default_settings.py
-------------------
SERVER_PORT = 8000
DOMAIN = 'example.com'
ADMIN_EMAIL = 'admin@example.com'
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
2.2 Install
pip install converge
3 .convergerc
.convergerc file helps converge choose application mode and in turn load correct settings file.
3.1 Supported directives
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.
Example
.convergerc ----------- APP_MODE = 'test' SETTINGS_DIR = 'appsettings'
4 Supported settings files
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
5 Guidelines
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``
6 Overriding settings
Defining module veriables in site_settings.py
6.1 Example
default_settings.py
SERVER_PORT = 9999
site_settings.py
SERVER_PORT = 8888
7 Overriding partial settings
Example:
default_settings.py
class DB:
HOST = 'db.example.com'
PORT = 1234
site_settings.py
DB.PORT = 1111
8 (Slightly) Advanced usage
In case if you want to keep all settings.py files in a directory. Use SETTINGS_DIR directive in .convergerc file.
8.1 Example
>> 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 | |
9 For Contributors
Running tests
git clone <repo>
cd converge
nosetests -xv tests.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file converge-0.7.tar.gz
.
File metadata
- Download URL: converge-0.7.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79fdacdbcd3166f08b4045890ed3b15f65ed6f8df27c04dd1782279be0c1da3f |
|
MD5 | 4d9d6ec88571da9ecbf2e04d6febd4fe |
|
BLAKE2b-256 | 6188d98b0406df6495d4b12d2b1ad691c40f6a47acc861b73b0fef1b4fd98557 |