Package: confusion
This package defines aConfigclass which allows you to employ an extended syntax in your TOML files.SyntaxDefaultsConsider this scrap of TOML:[A]

[B]
flavour = "strawberry"Confusionlets you add aDEFAULTsection just like the traditional Pythonconfigparser module:[DEFAULT]
flavour = "vanilla"

[A]

[B]
flavour = "strawberry"SubstitutionBy applying the extended substitution syntax, you can define a value in only one location and reference
it elsewhere (DRY principle):[A]
flavour = "strawberry"

[B]
flavour = ${A:flavour}Cross-compatible stringsMultiline strings have to be formatted to conform to bothconfigparserandTOMLsyntaxes:[caveat]
text = """
    Multiline strings
    are possible but
    indentation of these closing quotes
    is required.
    """UsageLet’s use this scrap ofCFNfor demonstration:text = """

[DEFAULT]
flavour = "vanilla"
flake = false

[A]
flavour = "strawberry"

[B]
flavour = ${A:flavour}
flake = true

"""The simplest way to construct a parser is via thefrom_stringclass method:from confusion import Config

conf = Config.from_string(text)Or, to read a file, just use thefrom_pathmethod:conf = Config.from_path("my_config.cfn")A Config object has all the methods of Python’s standardConfigParser class.
There is one difference; thesectionsattribute is a property which returns a dictionary:print(conf.sections)
>>> {'A': <Section: A>, 'B': <Section: B>}The hierarchical TOML data is available via the object’stablesproperty:print(conf.tables)
>>> {'A': {'flavour': 'strawberry', 'flake': False}, 'B': {'flavour': 'strawberry', 'flake': True}}Environment variablesYou can override settings in the Config object from a flat dictionary.
Keys in the dictionary are parsed for a separator (‘_’ by default) which denotes the section
in which the setting belongs.Suppose you want to avoid storing a password in this file:[DB]
USER = "postgres"You can define an environment variableDB_PASS=postgresand merge it in from there:import os

conf = Config.from_path("my_config.cfn")
conf.merge(os.environ)Only those variables with a corresponding section in the file will be merged in.
You can pass an alternative separator to themergemethod:conf.merge({"window.width": 800, "window.height": 600}, sep=".")LoggingThe Config file has a convenient method to set up your logs according to thelogging configuration schema.This means you can achieve complete configuration of your application in this single line of code:conf = Config.from_path("my_config.cfn").merge(os.environ).configure_logging(table_name="logging")Utilitiescfn2dotis a command line utility which generates a Grapviz.dotfile from a data graph in confusion format:$ python -m confusion.utils.cfn2dot --help

This utility translates a graph defined in a CFN file to an equivalent .dot

Usage:

    python -m confusion.utils.cfn2dot --label-graph Taxonomy --digraph taxonomy.cfn > taxonomy.dot

    dot -Tsvg taxonomy.dot > taxonomy.svg

       [-h] [--label-graph LABEL_GRAPH] [--label-inherits LABEL_INHERITS] [--cluster] [--digraph] input [input ...]

positional arguments:
  input                 Set input file.

options:
  -h, --help            show this help message and exit
  --label-graph LABEL_GRAPH
                        Set a label for the graph.
  --label-inherits LABEL_INHERITS
                        Set the label for an arc signifying an 'inherits' relationship.
  --cluster             Generate a clustered graph.
  --digraph, --directed
                        Make arcs directional.