Skip to main content

Multi-environment yaml settings following 12 Factor App methodology.

Project description

buba

Multi-environment yaml settings following 12 Factor App methodology.

Inspired by gem rubyconfig.

Features:

  • simple YAML config files
  • config files support inheritance and multiple environments
  • access config information via convenient object member notation
  • support for multi-level settings (Settings.group.subgroup.setting)

Install:

pip install buba

Usage:

Create config directories and files in project root directory:

.
+-- ...
+-- _config
|   +-- environments
|       +-- development.db.yaml
|       +-- production.db.yaml
|       +-- production.common.yaml
|   +-- db.yaml
|   +-- common.yaml
+-- ...
+-- ...
+-- main.py
  • files loaded by app env (default - development).

    • First loaded config/*.yaml files
    • Then loaded config/environment/{APP_ENV}*.yaml files (overrides values, there is option to override/merge list values)
    • Then check all loaded keys for overrides in environment variables (db.host will be mapped to PREFIX__DB__HOST)
  • app env defined by env ver APP_ENV (there is option to override)

  • app env config prefix default value is 'APP_CONFIG' (there is option to override)

  • app env config splitter default value is '__' (there is option to override)

from os import environ
from buba import Buba

if __name__ == '__main__':
    config = Buba(env_name='APP_ENV', prefix='CONFIG', splitter='::')
    assert config.app_name == 'my_app'
    assert config.db.host == 'localhost_default'
    assert config.db.user == 'user_development'
    assert config.db.password == 'password_development'

    environ['APP_ENV'] = 'production'
    config.load()

    assert config.app_name == 'my_app'
    assert config.db.host == 'localhost_default'
    assert config.db.user == 'user_production'
    assert config.db.password == 'password_production'

    environ['APP_ENV'] = 'production'
    environ['CONFIG::DB::HOST'] = 'production_host'
    environ['CONFIG::APP_NAME'] = 'production_app_name'
    config.load()

    assert config.app_name == 'production_app_name'
    assert config.db.host == 'production_host'
    assert config.db.user == 'user_production'
    assert config.db.password == 'password_production'

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

buba-0.0.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

buba-0.0.1-py2.py3-none-any.whl (4.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file buba-0.0.1.tar.gz.

File metadata

  • Download URL: buba-0.0.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

File hashes

Hashes for buba-0.0.1.tar.gz
Algorithm Hash digest
SHA256 df07489d4b6b1ea3746879c7a53dc56c070e1b19c081de79dcc6d96988b6f749
MD5 d8be88a6f99482874815cc5cffe89b66
BLAKE2b-256 992d925831cae8fc4a46f672e8ec025233c0cb18055aeb3de5f6bb867fc8601b

See more details on using hashes here.

File details

Details for the file buba-0.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: buba-0.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/2.7.12

File hashes

Hashes for buba-0.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 688a8727853cba5da2acafbfb43eaebbf433aa9051229f2fba210f95c6f179d9
MD5 8080f126e22dea61b4ff44e132ec7d39
BLAKE2b-256 5546eb82cd17fd44946f2e3ccf619d099d12a4d6e9dd6c3cafc2e0911144dfff

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