Skip to content
/ cfgtree Public

Python Application Configuration made easy (environment variable, command line and file parser)

License

Notifications You must be signed in to change notification settings

gsemet/cfgtree

Repository files navigation

cfgtree - App Configuration made easy

https://travis-ci.org/gsemet/cfgtree.svg?branch=master Documentation Status Pypi package MIT licensed

Description

This package provides an easy yet comprehensive way of describing, storing, parsing, modifying user configuration for a modern application.

It requires the following acknolegdments:

  • Application settings are stored in a hierarchical structure, they can be organized into group of settings, subgroups, and they entierely depends on the application itself.

    This structure is called in cfgtree a "bare configuration", or "configuration tree", and is described by a "model".

  • User settings may come from different inputs:

    • environment variables ("12-factors" approach). Example: MYAPP_VERBOSE.

    • command line argument. Example: --verbose

    • configuration storage such as file (json, yaml, ini) or configuration server. Example:

      {
          "verbose": true
      {

This allows you to define once your settings structure, and let the user of your application define the settings throught different ways. For instance, your application can read some settings through command line arguments, which is very useful for containerization of your application. It is indeed recommended by Heroku's 12 Factor Good Practices.

Describing your configuration through a model also allows to have a configuration validator without having to maintain both a file schema (ex: JSON Schema) and the parsing logic code.

Access to settings

In your application, an xpath-like syntax allows you to reach any item of the configuration: cfg.get_cfg_value("key1.key2.key3.item").

To modify a key configuration, use cfg.set_cfg_value("key1.key2.key3.item", "new_value"). File is actually written on call of cfg.save_configuration() or automatically when autosave is set.

See the documentation for full explanation.

Similar opensource projects

Documentation

Full documentation is provided on ReadTheDocs.

About

Python Application Configuration made easy (environment variable, command line and file parser)

Resources

License

Stars

Watchers

Forks

Packages

No packages published