Skip to main content

Flexible and extensible configuration reader for python.

Project description

Conflex

Flexible, extensible configuration reader for Python 3.6+ projects for multiple tree-like config sources.

Introduction

Conflex means "flexible configuration" it is a tool for parsing tree-like configuration with any level of depth. Thus, here the configuration is a tree structure with two types of nodes: Section and Option. Sections is used for grouping other nodes and option is a key-value pair. As it mentioned above depth is unlimited, section can have a child sections moreover options can have child options or sections. Checkout the "test/*' files for a more extended examples.

The option can contain list or single value. If list-typed option contains single value it is not cause an error this value will be treated as list with one element.

The input data is dict that contains tree representation for example { section : { key0 : value0, child_section { key00: value00, key01: value01 } } }. YAML and JSON parsers returns that kind of object.

Basic usage

# app/config.py
import conflex


def get_sourse(filename) -> dict:
    """
    Function that returns parsed to`dict` configuration.
    For example:
        {'main': {'master_ip': '192.168.0.1', 'master_port': 42}} 
    """
    ...


def load_config() -> Config:    
    config = Config((
        'main' >> Section() << (
            'master_ip'     << OptValue(iv_default='127.0.0.1'),
            'master_port'   << OptVInt(iv_required=True),
            'packet_size'   << OptVInt(iv_default='1KB') << (
                'source' << OptVChoice(
                    iv_default='conf',
                    il_mapping={'conf': 0, 'arg': 1})
        )))
    )
    sources = []
    sources.append(get_sourse('app_default.conf'))
    sources.append(get_sourse('app.conf'))
    config.load_dicts(sources)
    return config
# app/main.py
from app.config import load_config

SRC_CONF = 0
SRC_ARG = 1

config = load_config()
print(config['main/master_ip'])
sub_config = config.knot('main')
print(sub_config['port'])
if sub_config['packet_size/source'] == SRC_CONF:
    print(sub_config['packet_size'])  # will output `int` 1024
print(dict(config.items()))

Installation

pip install conflex

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

conflex-0.0.0a3.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

conflex-0.0.0a3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file conflex-0.0.0a3.tar.gz.

File metadata

  • Download URL: conflex-0.0.0a3.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for conflex-0.0.0a3.tar.gz
Algorithm Hash digest
SHA256 56c9e5b8db52d83beebc9ade5ba0c9619f726133a7950ee5c3763f95d29fcc85
MD5 efb8434b97fe1fb52f693f5a35d8d239
BLAKE2b-256 8501048381d58265cd15b31442fceb9e90ecf76a6d4d903844f37d715a343754

See more details on using hashes here.

File details

Details for the file conflex-0.0.0a3-py3-none-any.whl.

File metadata

  • Download URL: conflex-0.0.0a3-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.8.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for conflex-0.0.0a3-py3-none-any.whl
Algorithm Hash digest
SHA256 bb762aa64e1af158dfc3f51efa977a34456ecc4cc8246633133d451da16e0798
MD5 043626b57a0cbbbaed81e2e05a76606e
BLAKE2b-256 fa6cf98a504f71ff9eb6a11bfcdef9d40b7ff965c03aa92327f1e1c7ffce6bde

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