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.0.4.post2-py3.4.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | f181e4d7fc63c0b85e512fb9b9bc9ac629fe054c2aaac288a46c17712facd914 |
|
MD5 | cf06e1c5b8cfa2d0bb67e92794304aae |
|
BLAKE2b-256 | 62f89c09c7a30970b1c190ff975bc3507046654a3df4d71b3eff9dcd9124fdc2 |
Hashes for ConfigMaster-2.0.4.post2-py3.3.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | eb7ad85005be252e34e94c8dd405dcd31dc0cf0241207a332e9b9052fcc257ff |
|
MD5 | 83d5c3c1993b7ca08fba3b8e7497582b |
|
BLAKE2b-256 | 823e34e6fea31edc0a7632c15f7a5df2c0e7fb796b4915ddf8e99d6d64144617 |
Hashes for ConfigMaster-2.0.4.post2-py3.2.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55aedf019b2ed121312b461953cf24727c76fa7e1d794794e2b09056daf32d62 |
|
MD5 | 0bce142db9bcab1fc495a4d133b8fa06 |
|
BLAKE2b-256 | 5c2b88586322bab55c4ff653bca4344193ea2d12cc08321186b066f0c9a28caf |
Hashes for ConfigMaster-2.0.4.post2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7e8d2cd18ab25138acf63baef337d62ff6b336b68905e02a6e8e430c6e8b4153 |
|
MD5 | 9b3e78d8890d2ed2144ad5f44065d681 |
|
BLAKE2b-256 | d6da040ea124f9a0365b0130f7753f40537eab9eb451bdee0ce44a2805c129c4 |