Python library to save and fetch configuration data in a standard/conventional path and format.
pip install cfgsaver
Import the cfgsaver
module to save/read configuration values in your source files:
from cfgsaver import cfgsaver
def save_config():
# saves configuration data to ~/.config/<your_package>/cfg.json
# unless cfgpath parameter is overridden:
config = {
'name': 'Prahlad',
'language': 'Python',
'framework': 'Flask'
}
cfgsaver.save('<your_package>', config)
def get_config():
# gets configuration data from ~/.config/<your_package>/cfg.json
# unless cfgpath parameter is overridden:
config = cfgsaver.get("<your_package>") #returns None if config file doesn't exist
def prompt_user():
# prompts user for config keys and saves resulting values as per save_config()
config = {
'name': '',
'language': '',
'framework': ''
}
config = cfgsaver.get_from_cmd("<your_package>", config.keys())
For information on shipping default configuration data packaged with your app using setup.py
, read detailed docs.
Detailed docs are available at https://cfgsaver.readthedocs.io/en/latest/.