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

Project configuration variables are declared beforehand and inferred from environment variables or configuration files. Useful while developing and deploying( CI/CD) django web-apps

Install

pip install dynamic-conf

Features

  • supports .env or .py files
  • supports casting with type annotations
  • 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 order of preference is env variables > env.py
  • Attributes are lazily evaluated.

Getting Started

  • You need to subclass the Config class.
  • The config file should define all the variables needed for a project.
# project/conf.py

from dynamic_conf import Config, REQUIRED

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 # Python 3 only
    AN_SECRET_KEY = REQUIRED # Python 2 & 3
  • to create project/env.py just run with the path to CONFIG class's module
# you could pass environment variables or set already with export
env DB_PASS='123' dynamic-conf project/conf.py

dynamic-conf project/conf.py DB_USER='user-1' DB_PASS='123' # pass as list of key-value pair

#to filter environment variables with a prefix
env VARS_PREFIX="PROD_" dynamic-conf project/conf.py PROD_DB_USER="user-2"

Usage

  • 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.4.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

dynamic_conf-0.4.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dynamic-conf-0.4.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.3 CPython/3.8.1 Linux/5.5.7-1-MANJARO

File hashes

Hashes for dynamic-conf-0.4.0.tar.gz
Algorithm Hash digest
SHA256 30871fae1d151239610a03cdca7048160ce2097f79a16d1fae6a1bd56dcb7d0e
MD5 c74dea02257950504ea7acc5ac365046
BLAKE2b-256 220d9315205139d58f9955f946b51352a995853d58f18cfc4aedc672646c51d6

See more details on using hashes here.

File details

Details for the file dynamic_conf-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: dynamic_conf-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.0.3 CPython/3.8.1 Linux/5.5.7-1-MANJARO

File hashes

Hashes for dynamic_conf-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3f7fa88c72a65d573d6d9f4b500c2d51c3eb2ae2728ebfa251ed7678f509a9ce
MD5 f1754e1fbde7cc52dac692bcde7f9565
BLAKE2b-256 72cfa9c130b36e24c06b26f26d9222e877c9afef9d6f8ea8f8b7afcc6b5022be

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