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.0.tar.gz (7.8 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.0-py3.4.egg (22.3 kB view details)

Uploaded Egg

ConfigMaster-2.2.0-py3.3.egg (22.5 kB view details)

Uploaded Egg

ConfigMaster-2.2.0-py3.2.egg (22.1 kB view details)

Uploaded Egg

ConfigMaster-2.2.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file ConfigMaster-2.2.0.tar.gz.

File metadata

  • Download URL: ConfigMaster-2.2.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ConfigMaster-2.2.0.tar.gz
Algorithm Hash digest
SHA256 da41ef67172a49c4cf96fb8836218bc3c46f1b053c582787d5b19eb9e5ddb0f8
MD5 0336ad6d0c1c4adcd0ac459d8906456e
BLAKE2b-256 ca9b82da742eb3bb95600cd629dbef12aa9c01b155e4bb1f8f1738660b6ec78c

See more details on using hashes here.

File details

Details for the file ConfigMaster-2.2.0-py3.4.egg.

File metadata

File hashes

Hashes for ConfigMaster-2.2.0-py3.4.egg
Algorithm Hash digest
SHA256 d354647a7eff095b1dcbcd7c3443754aa31081910d0a8567ad629f918f10c400
MD5 8a69f0c618def1e1643c8d6f0a02d5f9
BLAKE2b-256 7864804f6f9988c2d4c82aecdacba30eb133e6f82e13cbe836d732792bc71ddf

See more details on using hashes here.

File details

Details for the file ConfigMaster-2.2.0-py3.3.egg.

File metadata

File hashes

Hashes for ConfigMaster-2.2.0-py3.3.egg
Algorithm Hash digest
SHA256 4070628781a804bcfd3a5e522ee4fbd0278c8f76fdef491896f5c4b8956e5af4
MD5 67523d9f32a911f0a72e21d7de4a1768
BLAKE2b-256 69a265ebf494d78f7c4aa1eec0c7fab886a0c12ce6ca634bf867649885366940

See more details on using hashes here.

File details

Details for the file ConfigMaster-2.2.0-py3.2.egg.

File metadata

File hashes

Hashes for ConfigMaster-2.2.0-py3.2.egg
Algorithm Hash digest
SHA256 688422c9660269eccbe2d7c85efe1a1fd0ccf6835738811198d447cf979df290
MD5 25b87eaf816f66c993040aaf971f0211
BLAKE2b-256 402e473e83fc1e6e72b9cc6f32c51c4df1e7d2851bc204caf4a07aedfa75be6c

See more details on using hashes here.

File details

Details for the file ConfigMaster-2.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ConfigMaster-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e02bf2fc79ec3719fb690a2967489b62b5edc3d6eb8d4b233b56c1a1a785e00c
MD5 adbabed2c4268b81a795726f19671e5e
BLAKE2b-256 fcac045efe6d61278efe293101574a30fc799c2145995f5573e70314bc428409

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