Programmatic configuration library for Python 3.
Project description
ConfigMaster
What is ConfigMaster?
What is supported
ConfigMaster supports the following formats built-in:
YAML Config Files (through the PyYAML module)
JSON Config Files (through json)
INI Config Files (through ConfigParser)
Networked versions of YAML/JSON files.
Support for different types of config files grows all the time - feel free to fork and add support!
TODO
[STRIKEOUT:Add in support for python ConfigParser formats] Added in version 1.4.0
[STRIKEOUT:Add in networked JSON support] Added in version 1.3.0
Add more docstrings
Make proper documentation
[STRIKEOUT:Add tests] Added in version 1.3.1
How to install
After installing, running the tests is recommended.
py.test -rfEsxXw -v --strict test.py
How to use
ConfigMaster handles everything for you. Simply specify the location of your file, and the values will be automatically loaded for you.
>>> from configmaster import YAMLConfigFile >>> cfg = YAMLConfigFile.YAMLConfigFile("test.yml") # Created automatically if it doesn't exist
Networked config files are supported too.
>>> from configmaster import JSONConfigFile >>> cfg = JSONConfigFile.NetworkedJSONConfigFile("http://example.com/data.json")
To access config values, get the attribute you want from the config object stored.
# YAML data is {"a": 1, "b": [1, 2], "c": {"d": 3}} >>> cfg.config.a 1 >>> cfg.config.b[1] 2 >>> cfg.config.c.d 3
To populate your config data, just pass a dict to initial_populate. If the file is empty, this gives it default values, and returns True. If it isn’t, nothing happens. Note: This will fail with an exc.NetworkedFileException on networked files!
>>> pop = cfg.initial_populate({"a": 1, "b": [1, 2], "c": {"d": 3}) >>> if pop: cfg.dump() and cfg.reload() # Dump data and reload from disk.
To save your data, run .dump().
>>> cfg.dump()
Have a networked file that you need to save? Use the method save_to_file.
>>> cfg.save_to_file("example.json")
Need to get the raw dict form of a ConfigKey? Use .dump() on that!
>>> cfg.config.dump() {"a": 1, "b": [1, 2], "c": {"d": 3} >>> cfg.config.c.dump() {"d": 3}
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 Distributions
Hashes for ConfigMaster-2.3.4.post1-py3.4.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | c50bb87566c91e683eab70930a0583d6c0d8bbbea3aa07d9b1e649398a8a6e64 |
|
MD5 | 030dbbfb068ffa7b5748207308674046 |
|
BLAKE2b-256 | 20638ccc4d3e2aa9b7cb77679f13cf78e9104174c3508420598c33ed32809203 |
Hashes for ConfigMaster-2.3.4.post1-py3.3.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 91835e7cc122811756fc59fbead065984054c2e1bb4e8d8456d9fa64745b603f |
|
MD5 | 86646d89cf8822ea944b7203af70517d |
|
BLAKE2b-256 | 6c0b1536daa3b712c4b9f56d260dc52789c69bc67c489821d59fdd3147943ba8 |
Hashes for ConfigMaster-2.3.4.post1-py3.2.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9070a9dbd00f775eacfe826e5a38f9dfe60af6b95018f3e8eb424e21faf8ebd9 |
|
MD5 | e7976e964bf72aeb735882e772bc4967 |
|
BLAKE2b-256 | f19e8d5c0619b7350cf312a0ef2cd8d99216a4b3ab863f7788b783b2926beaf7 |
Hashes for ConfigMaster-2.3.4.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b177807f5819f0ca0ea6cd82869fb19458148c1e0955a9f1c3bfeb13ad1b5638 |
|
MD5 | 8f5f058c6fcd4050abbe3ae133e46bd6 |
|
BLAKE2b-256 | 28878817c91bba23252860dd28a6e70094bc9ceba2699623f724529b76784d35 |