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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for config_env-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f1d9f152f33a4817a919dcfa631f325db022f78e7a066a9a25b7071656a0b732 |
|
MD5 | 4773fa38c1998ed0dcf0c7c0366c04ad |
|
BLAKE2b-256 | caa22a54ac61f3c3bc956c93669a1412555ce0ada62d8cd2e901e875f4e5adaf |