Flexible tree-like configuration reader.
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file conflex-0.0.0a2.tar.gz.
File metadata
- Download URL: conflex-0.0.0a2.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d66f0c28c6a1d5d87155a6f1f0712c9b969999f580e1656b60ba6c6b333d8455
|
|
| MD5 |
41b00c1237acf1aef13f8771dadf1446
|
|
| BLAKE2b-256 |
fa6936d8c9a3de878c93448f31f5603239fbded44ea53e12047ae82e38f1478b
|
File details
Details for the file conflex-0.0.0a2-py3-none-any.whl.
File metadata
- Download URL: conflex-0.0.0a2-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2be7891590b25ca1b75b6a94ea58ddcb907a7277b38a17fba71443587ed133b6
|
|
| MD5 |
90ffc06348a8c43d6a2c0233079b0d80
|
|
| BLAKE2b-256 |
139ec26d50ac5eeddaa86f9efe71af49213a24f7ec9c283d677fae4588aad2ed
|