Skip to main content

Easy to manage Config variables separate from App code. Useful while developing and deploying( CI/CD) django web-apps

Project description

dynamic-config

Easy to manage Config variables separate from App code. Useful while developing and deploying( CI/CD) django web-apps

Usage

  • You need to subclass the Config class.
  • Any configuration would be loaded from python config file (default: env.py) from the same folder where library is inherited. This file should not be committed to version history.
  • You also don't need to include a sample file. Since the Config object would be able to generate env.py itself.
  • It also loads Configuration variables from environment variables. The preference is env variables > env.py
  • The config file should define all the variables needed for a project.
  • It can also define a prefix to limit environment variables searched.
# project/conf.py

from dynamic_conf import Config

class CONFIG(Config):
    """singleton to be used for configuring from os.environ and env.py"""

    # default settings

    ENV = "prod" # optional field with a default value

    DB_NAME = "db"
    DB_HOST = "127.0.0.1"
    DB_USER = "postgres"
    DB_PASS = None # even None could be given as default value

    SECRET_KEY:str # required field. Note: it will not work in Python 2 because
  • to create project/env.py just run
# you could pass environment variables or set already with export
env DB_PASS='123' dynamic-conf

# or you could pass as list of key-value pair
dynamic-conf DB_USER='user-1' DB_PASS='123'

# to filter environment variables with a prefix
env VARS_PREFIX="PROD_" dynamic-conf PROD_DB_USER="user-2"
  • To use the config simply import and use particular attribute
# project/settings.py
from conf import CONFIG
DATABASES = {
    "default": {
        "ENGINE": "django.contrib.gis.db.backends.postgis",
        "HOST": CONFIG.DB_HOST,
        "NAME": CONFIG.DB_NAME,
        "USER": CONFIG.DB_USER,
        "PASSWORD": CONFIG.DB_PASSWORD,
        "PORT": "5432",
    }
}

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

dynamic-conf-0.1.1.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

dynamic_conf-0.1.1-py2.py3-none-any.whl (5.2 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dynamic-conf-0.1.1.tar.gz.

File metadata

  • Download URL: dynamic-conf-0.1.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Linux/5.2.11-1-MANJARO

File hashes

Hashes for dynamic-conf-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8a7ebab7233fe2357db55cc8889b907b4f17373edbbd3323753a0d87f342059f
MD5 8a624f9ca0af8c8dffe0b2bec74adf07
BLAKE2b-256 73bcf20b86e2d675e891f26f8d9c399c005c77858608a7c70cec272beb4c57b1

See more details on using hashes here.

File details

Details for the file dynamic_conf-0.1.1-py2.py3-none-any.whl.

File metadata

  • Download URL: dynamic_conf-0.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/0.12.17 CPython/3.7.4 Linux/5.2.11-1-MANJARO

File hashes

Hashes for dynamic_conf-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 e38df941061f8c9195526a2291126262bd51f47ed06708f614aaea088c502dc0
MD5 e53f61c5dda9765a58486b883a76768a
BLAKE2b-256 442bbc11e3edda9f0a1f73b30df9b109ffe9a65c68f0ab0146c294bedf4ab22c

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