Skip to main content

Ultra simple settings management for (only) Python apps

Project description

1 Getting started

1.1 Setup

pip install converge

1.2 Usage example

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

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

3 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

4 Setting mode

Create a file .convergerc. This file supports a directive APP_MODE

Valid values are

  • prod

  • dev

  • test

  • staging

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

5 Overriding settings

Defining module veriables in site_settings.py

5.1 Example

default_settings.py

SERVER_PORT = 9999

site_settings.py

SERVER_PORT = 8888

6 Overriding partial settings

Example:

default_settings.py

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

site_settings.py

DB.PORT = 1111

7 (Slightly) Advanced usage

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

7.1 Example

>> cat .convergerc

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

8 For Contributors

Running tests

git clone <repo>
cd converge
nosetests -xv tests.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

converge-0.5.tar.gz (3.2 kB view details)

Uploaded Source

File details

Details for the file converge-0.5.tar.gz.

File metadata

  • Download URL: converge-0.5.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for converge-0.5.tar.gz
Algorithm Hash digest
SHA256 ab6253885d6640bee09a136e393838ee14050ac33c87757526f3da10049307dc
MD5 4a8aa5e2c55b4c465d8d507d0dc330c4
BLAKE2b-256 d202988e410bfa7b603581c169395678751290d182fd9d58ce3f6140be449cef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page