Skip to main content

Programmatic configuration library for Python 3.

Project description

ConfigMaster

Build Status PyPI version PyPI DailyDownloads

What is ConfigMaster?

ConfigMaster is a simple library for accessing config files programmatically. No longer will you have to mess with list lookups and dict lookups when you wish to load a config file.
Instead, objects in the file are accessed as simple class attributes.

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

For the latest stable version uploaded to PyPI, use:
pip install configmaster
For the latest stable version uploaded to bitbucket, use:
pip install git+https://github.com/SunDwarf/configmaster
For the latest dev version, use:
pip install git+https://github.com/SunDwarf/configmaster@dev

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ConfigMaster-2.2.2.post2.tar.gz (7.9 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

ConfigMaster-2.2.2.post2-py3.4.egg (22.4 kB view details)

Uploaded Egg

ConfigMaster-2.2.2.post2-py3.3.egg (22.7 kB view details)

Uploaded Egg

ConfigMaster-2.2.2.post2-py3.2.egg (22.2 kB view details)

Uploaded Egg

ConfigMaster-2.2.2.post2-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file ConfigMaster-2.2.2.post2.tar.gz.

File metadata

File hashes

Hashes for ConfigMaster-2.2.2.post2.tar.gz
Algorithm Hash digest
SHA256 4bdddb81bcef7361debaa4807c8d5bbb02f18175bc6fe509d615335c793304d2
MD5 ff961bb55477eeff557c3e1a9576c3c4
BLAKE2b-256 2e5f75d6f8806f2fa629a54490286253b8335ad62a46e7b3e2aa5086d79176b7

See more details on using hashes here.

File details

Details for the file ConfigMaster-2.2.2.post2-py3.4.egg.

File metadata

File hashes

Hashes for ConfigMaster-2.2.2.post2-py3.4.egg
Algorithm Hash digest
SHA256 b5cacb46cc73721ba77f147617b57d3a535b7ee4037374978cde896006292fac
MD5 65fc1f8409b5b6effde010fa17c12d00
BLAKE2b-256 8bb1321237cdccd4600c39768444c7cbe964b125097bec71277b3e1895adb398

See more details on using hashes here.

File details

Details for the file ConfigMaster-2.2.2.post2-py3.3.egg.

File metadata

File hashes

Hashes for ConfigMaster-2.2.2.post2-py3.3.egg
Algorithm Hash digest
SHA256 16e6208adece4f3115d68f732c21b6ac7feb3c645ff3be05b8b61ab4520c663c
MD5 708665da5cbe973dc34928e79f6240b2
BLAKE2b-256 b95c81e2023c37efdf0c218b4e61046c4d09957d73003011282c65e5c4ff3868

See more details on using hashes here.

File details

Details for the file ConfigMaster-2.2.2.post2-py3.2.egg.

File metadata

File hashes

Hashes for ConfigMaster-2.2.2.post2-py3.2.egg
Algorithm Hash digest
SHA256 747ec523e473a74de54a57ebabf70466d46613e533156f0f0fa116be7e056966
MD5 b4cd7c1836a35729c4c74971ff64a54f
BLAKE2b-256 7c3dac442bcb7e1121963f1708cfb2599b4ac23d8568306684dbd9335917135a

See more details on using hashes here.

File details

Details for the file ConfigMaster-2.2.2.post2-py3-none-any.whl.

File metadata

File hashes

Hashes for ConfigMaster-2.2.2.post2-py3-none-any.whl
Algorithm Hash digest
SHA256 824212ba34f37b658e0bc5ff5195043cd61d4e7be98c29af6b7f678761d9ec52
MD5 d4b2df5d2610c4570b80bcc40631b001
BLAKE2b-256 0edf194804cbcaf8201538311f5ba89035fe58b54f2e1fbfb313aa3ac9ec1396

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page