Skip to main content

Automatic configuration file, command line, environment variable parser

Project description

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

Description

This package provides an easy yet comprehensive way of describing, storing and parsing a user configuration.

It requires the following acknolegdments:

  • Application settings actually represents 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”.

  • 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
      {

Similar opensource projects

Overview

Please go to ReadTheDocs for full, up-to-date reference documentation.

Here is just a quick overview of cfgtree.

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. User can set this setting by:

  • environment variable APPLICATIONNAME_COUNT (where APPLICATIONNAME is an optional, developer-defined prefix added to every environment variable of the application 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, let’s imagine the ‘count’ setting is set in a group called ‘general’:

  • environment variable is: APPLICATIONNAME_GENERAL_COUNT

  • command line argument is: --general-count

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

    {
        "general": {
            "count": 1
        }
    }

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.

cfgtree allows complete customization of the file storage, developers can even develop their own.

Another typical file format for configuration is YAML, which is more human readable and allow inserting comments and so. INI files is often found as configuration format, or TOML.

But, ultimately, all file formats actually store settings in 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

Access to settings

In your application, an xpath-like syntax allows you to reach any item of the configuration: <key1>.<key2>.<key3>.<item>. See the documentation for full explanation.

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-1.0.1.tar.gz (21.2 kB view details)

Uploaded Source

Built Distribution

cfgtree-1.0.1-py2.py3-none-any.whl (18.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

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

File hashes

Hashes for cfgtree-1.0.1.tar.gz
Algorithm Hash digest
SHA256 ea0a10b1a986d0a250bd29b76a636d9fa1ac12d9988101093b67172afc9e6fe2
MD5 edf35443d65b8fbdd1e26311fd66c53a
BLAKE2b-256 f08a692765ef27107407a4d64fb287355dd91b591adc39a31a9729240bf8e9ef

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for cfgtree-1.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 ef948735ba9e65b29a4b0c9a7db7b14d8c3c931cf66c12cb6f996686b034f7dc
MD5 5206cc5f4a200d3dd59320225b54b6b5
BLAKE2b-256 941907f7407243b528b9fd8eb44aca5fc9d1483a33214d80ca8cc3b7c107b0e7

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