Skip to main content

Manage enviroment variables

Project description

About

Package to manage environment variables similar to npm config from nodejs

Start

pip install config_env
mkdir configenv
vi configenv/default.json
// default.json
{
    // Customer module configs
    "Customer": {
        "dbConfig": {
            "host": "localhost",
            "port": 5984,
            "dbName": "customers"
        },
        "credit": {
            "initialLimit": 100,
            // Set low for development
            "initialDays": 1
        }
    }
}
vi configenv/production.json
{
    "Customer": {
        "dbConfig": {
            "host": "prod-db-server"
        },
        "credit": {
            "initialDays": 30
        }
    }
}

And if is necessary to hide secret values, it is recommended to use custom_environment_varibles.json to get environment variables:

vi configenv/custom_environment_varibles.json
{
    "Customer": {
        "dbConfig": {
            "user": "MY_USERNAME",
            "password": "MY_PASSWORD"
        }
    }
}

Values preference order:

  • custom_environment_varibles -> production -> default

If custom_environment_varibles.json file does not exist or do not contain some key:value, it will come from produciton.json.

If producion.json file does not exist or do not contain some key:value, it will come from default.json.

Using config_env

The name of the environment variable PYTHON_ENV must be the same as your json file created. If PYTHON_ENV is not defined, the values defined in default.json will be used.

Example:

export PYTHON_ENV=production
# app.py
from config_env import ConfigEnv

config = ConfigEnv()

customer_host = config.get("Customer.dbConfig.host")

customer_credit = config.get("Customer.credit")

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

config_env-0.0.19.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

config_env-0.0.19-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file config_env-0.0.19.tar.gz.

File metadata

  • Download URL: config_env-0.0.19.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for config_env-0.0.19.tar.gz
Algorithm Hash digest
SHA256 cdc9079c2c2d8eb7b075d48414f07fcd3a590ecc153346ff0448febff84dfb5c
MD5 7bdfdcf69d7258e75ebdb1d898e30d4e
BLAKE2b-256 1217beb20010a1799e1be22c6fa4a9a0896a8407f670c2af19729c294aef52dd

See more details on using hashes here.

File details

Details for the file config_env-0.0.19-py3-none-any.whl.

File metadata

  • Download URL: config_env-0.0.19-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for config_env-0.0.19-py3-none-any.whl
Algorithm Hash digest
SHA256 80236d39417484d934a522720612b46ac2605ca90a3363e131a32abff58143fd
MD5 5b41a713afe6838ee08f90897700692e
BLAKE2b-256 0daeb0e540336ca2a37d56d351677dd1d2441de358e7b58a1462d127ce020dcf

See more details on using hashes here.

Supported by

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