Facilitates a convenient use of configuration files
Project description
conf
A very simple and lightweight configuration loader and parser for Python.
Supports:
ini files (*.ini)
json files (*.json)
yaml files (*.yml, *.yaml)
Installation
Bare installation:
pip install conf
Installation with support for YAML:
pip install "conf[yaml]"
Usage
Starting your app
Start your app with your configuration file:
python your_app.py --config your_config.yml
Or:
python your_app.py --config config_env_var
The --config argument can be:
a relative path to a file;
an absolute path to a file;
the name of an environment variable which value holds one of the above.
You are allowed to provide multiple configuration names (separated by a single space), in which case any setting of a former configuration file can be overwritten by a setting of a later configuration file (if the name of that setting is identical).
Once you have supplied your application with some configuration, you can fetch the settings of that configuration. There are three options of how to do that.
Fetching your setting (option 1)
Simply get your setting from the conf module:
import conf
your_setting = conf.your_setting
Fetching your setting (option 2)
Import your setting directly:
from conf import your_setting
Fetching your setting (option 3)
You can provide a default value if you are not sure the setting will be present:
import conf
your_setting = conf.get('your_setting', 'your default value')
Note: If you use an ArgumentParser in your own application for other purposes, you must use the parse_known_args() method of the parser.
Fetching your setting (option 4)
You can get the configuration as a dictionary and get your setting as you would get any value from a dict:
import conf
conf_dict = conf.asdict()
your_setting = conf_dict.get('your_setting', 'your default value')
Meta
This lib was designed and written in 2018 by finetuned89 and ramonhagenaars.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file conf-0.4.1-py3-none-any.whl
.
File metadata
- Download URL: conf-0.4.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d17b309d74ec1cf71ba885c97619bd4d9f938036c7830a715b25ed75defe95a4 |
|
MD5 | 80806b61f962556c877e992290d6b480 |
|
BLAKE2b-256 | 2ff377a040c3efb4d33d824a68d3e1680585041d359d55df84115bad1538cdaa |