Skip to main content

Automatic configuration file, command line, environment variable parser

Project description

https://travis-ci.org/Stibbons/cfgtree.svg?branch=master Documentation Status https://coveralls.io/repos/github/Stibbons/cfgtree/badge.svg Pypi package MIT licensed

Description

This module provides an easy yet comprehensive way of defining a configuration tree for any application.

It requires the following acknolegdment:

  • Application settings are organize in a hierarchical structure, dependend of the application itself. This structure is called in cfgtree: “bare config”.

  • User settings may come from different inputs:

    • environment variables (12 factors approach)

    • command line argument

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

Similar opensource projects

Configuration Storage

The trivial storage is a simple json file. The complete settings are placed inside it, such as:

{
    'setting1': 'value1',
    'setting2': 'value2',
    'setting3': 'value3',
}

But developer may want to organize in a more hierarchical structure, splitting into different files, etc.

Another typical file format for configuration is YAML, which is more human readable and allow inserting comments and so.

But, ultimately, all file format actually stores a hierarchical configuration.

Current Support:

  • single Json file

Future support:

  • Yaml file (with inplace save keeping comments and overall organization)

  • Set of Yaml files

  • Configuration server

Configuration Tree Description

Configuration hierarchy is to be described in a cfgtree.EnvironmentConfig inherited instance, inside the member .cfgtree, using helper classes such as StringCfg, ‘IntCfg’, ‘UserCfg’ or ‘PasswordCfg’. Each setting can be set by environment variable, command line parameter or by the storage file(s) itself.

Let’s take an example of an item defined at the first level of the hierarchy. It is defined as a ‘IntCfg’ with name ‘count’. It can be set by the following:

  • environment variable APPLICATIONNAME_COUNT (where APPLICATIONNAME is an optional developer-defined prefix added to every environment variable to avoid conflicts)

  • command line argument --count

  • item count at the first level of a json file

Hierarchical structure is reflected in these different ways, to avoid conflicts. Now, the ‘count’ setting is set in a settings section called ‘general’:

  • environment variable: APPLICATIONNAME_GENERAL_COUNT

  • command line argument: --general-count

  • Json has a first level named general, and inside one of the items is called count.

XPath syntax

A xpath-like syntax allows to reach any item of the configuration: <key1>.<key2>.<key3>.<item>.

Documentation

Full documentation is provided on ReadTheDocs.

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

cfgtree-0.1.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

cfgtree-0.1.0-py2.py3-none-any.whl (13.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file cfgtree-0.1.0.tar.gz.

File metadata

  • Download URL: cfgtree-0.1.0.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cfgtree-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ef04550bc62fef9e960c57d5e9872af5598a82e1410d79438c83652725b9d4aa
MD5 31e34892d57163a1ca92fdaabedeeca4
BLAKE2b-256 25cd2828670379793deb32e3e8d650fc0a8606447e023d96b8698338e3780827

See more details on using hashes here.

File details

Details for the file cfgtree-0.1.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for cfgtree-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f61e6668fd5e148a6f7423379ae9badaba07e2f890eb5bcb3d9f2d1b66e03c0b
MD5 22280dee808a2020fe31b2331a13f2a2
BLAKE2b-256 d85f0ad546c4a5a242e439114208978d065a3d3ae7aaf2d1147cb575209c3654

See more details on using hashes here.

Supported by

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