A wrapper of python-configuration
Project description
Python Configuration Wrapper
This lib is basically a wrapper of the python-configuration.
It aims at making configuration easy !
Features
Read multi-level configuration values from multiple sources (precedency ordered):
-
Command line arguments given by
--additional-config
or-C
parameter.Example:
python app.py -C "database.dialect=postgresql" --additional-config "database.host=postgres.mydomain.org" -C "database.user=admin"
-
Environment variables starting with prefix set in the
CONFIG_PREFIX
environment variable. Level separator is__
(double underscore).Example:
CONFIG_PREFIX=TEST TEST__database__user=root python app.py
-
Config directories given by
--config-path
or-P
parameter. The value of this parameter must be a directory path in which the sub-directories are multi-level keys, and plain-text files content are values. It's very practical when using secrets in containers.Example:
mkdir /var/run/secrets/database -p echo -n 123456 > /var/run/secrets/database/password python app.py --config-path /var/run/secrets
-
Config files given by
--config-file
or-F
parameter. File formats must be among those handled by python-configuration:- json
- ini
- yaml
- toml
- python
Example:
python app.py -F config.json --config-file config.yaml
If no config file is given, the lib will look for config.{yaml|json|ini|toml|python} in the working directory.
Installation
pip install python-configuration-wrapper
Usage
# import the config object from the module
# you can do this in every python file you want
from python_configuration_wrapper import config
# get some value from a multi-level key
myvalue = config.myfirstlevel.mysecondlevel.mykey
Example
See test
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 python-configuration-wrapper-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a09a69772f7d87146d67f19b446210158a2b792b37df5a59940ed1b0317b70dc |
|
MD5 | 6371e3fd0a97d13d9e15ff581e8e99b2 |
|
BLAKE2b-256 | 0d5b97c55f3ce678e4555da4637dfb8230645ffe1c21836fe0979b2cfe2d5aa1 |
Hashes for python_configuration_wrapper-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 229a7ef46a19b5323b8feb9b590bddc1d8703cb53b60d642f008097f9898a1d8 |
|
MD5 | 8b9f5a929451912033cce474d5d62771 |
|
BLAKE2b-256 | ea0d9de53f8bf6cb75b759d4596d0e4194ee409fefcefbe45dcb05d5d319b9f8 |