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.5.post1-py3.4.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | c760ae99ec299d7edc5670812adde8998200e48681f4921be6c889c10b225b9e |
|
MD5 | ba64eddb2353db65f58ce881504c511e |
|
BLAKE2b-256 | d3c3b2d5aa0929210e1d1d6cfde366539fcc11b527f4e55f0938ab6964462497 |
Hashes for ConfigMaster-2.3.5.post1-py3.3.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | dbef3de075f0c67f2f9e77495ce093f4eaf66fd1c5c266f6f73198bc41fdb40f |
|
MD5 | 9618164438654fdf803b6c88ca4e8980 |
|
BLAKE2b-256 | 7e83d7faa3d4c2410da5d246d164c7a4f203b26297f85f6fadc755b4e0ab3051 |
Hashes for ConfigMaster-2.3.5.post1-py3.2.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f6986d3f71e1918000b87bd4f15ec12a7008359b6c4daaa4106e5366f16f2ed |
|
MD5 | 29cae924699bfb8dff8e98efbe4f92cd |
|
BLAKE2b-256 | 95e41ae659099578e6c448e87a4bedb18642233b387154cadf33fdcd66e46f8c |
Hashes for ConfigMaster-2.3.5.post1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dc14d5e4a24db911547b11d0b12b6df88d669ae52068ac7c24c5bb55de924a9 |
|
MD5 | 6fb366d2b7281c24b7d5ddb518202136 |
|
BLAKE2b-256 | 1da8f347c0065b7c30105bf4b218b3d67adf19b0d4abde7c148353bedeba36a7 |