Skip to main content

Simple layered configuraion tool

Project description

Compendium

License Build Status codecov

Overview

Compendium is a layered configuration management tool. It has the capability to manage configuration files writen in JSON, TOML, XML and YAML. Settings from these configuration files can then be managed easily with the help of dpath.

Documentation

https://kuwv.github.io/python-compendium/

Install

pip install compendium

Manage a configuration file

>>> import os
>>> from compendium import ConfigFile

>>> basedir = os.path.join(os.getcwd(), 'tests')
>>> filepath = os.path.join(basedir, 'config.toml')

>>> cfg = ConfigFile(filepath)
>>> settings = cfg.load()

Simple lookup for title
>>> settings['/title']
'TOML Example'

Query values within list
>>> settings.values('/servers/**/ip')
['10.0.0.1', '10.0.0.2']

Check the current server IP address
>>> settings['/database/server']
'192.168.1.1'

Update the server IP address
>>> settings['/database/server'] = '192.168.1.2'
>>> settings['/database/server']
'192.168.1.2'

Check the database max connections
>>> settings['/database/connection_max']
5000

Delete the max connections
>>> del settings['/database/connection_max']

Check that the max connections have been removed
>>> settings.get('/database/connection_max')

Manage multiple layered configurations

The ConfigManager is a layered dictionary mapping. It allows multiple configurations to be loaded from various files. Settings from each file is overlapped in order so that the first setting found will be used.

>>> import os

>>> from compendium import ConfigManager

Reference config files from examples
>>> basedir = os.path.join(os.getcwd(), 'examples', 'config_manager')
>>> config1 = os.path.join(basedir, 'config1.toml')
>>> config2 = os.path.join(basedir, 'config2.toml')

Retrieve settings from config files
>>> cfg = ConfigManager(name='app', filepaths=[config1, config2])

Get using dpath
>>> cfg.get('/default/foo2')
'bar2'

Lookup with multi-query
>>> cfg.lookup('/example/settings/foo', '/default/foo')
'baz'

Manage nested configurations

>>> import os

>>> from anytree import RenderTree
>>> from compendium.config_manager import ConfigManager, TreeConfigManager

>>> basedir = os.path.join(os.getcwd(), 'examples', 'tree')

>>> cfg = TreeConfigManager(
...     name='fruit',
...     basedir=basedir,
...     filename='node.toml',
...     load_root=True,
...     load_children=True,
... )

>>> cfg.defaults == {}
True

>>> 'succulant' in cfg['/fruit/children']
True

>>> succulant = cfg.get_config('/fruit/succulant')
>>> succulant.name
'succulant'

Manage configurations using Hierarchy File System (HFS)

TBD

Development

python -m venv .vev
pip install -e .[dev]
python -m doctest README.md

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

compendium-0.1.4.tar.gz (34.4 kB view details)

Uploaded Source

Built Distribution

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

compendium-0.1.4-py3-none-any.whl (26.8 kB view details)

Uploaded Python 3

File details

Details for the file compendium-0.1.4.tar.gz.

File metadata

  • Download URL: compendium-0.1.4.tar.gz
  • Upload date:
  • Size: 34.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for compendium-0.1.4.tar.gz
Algorithm Hash digest
SHA256 8c3fdb93e45c5f18fd235b0a058af3a393c6fe1c6b96005393f7d074ebf45140
MD5 3435897c2ce32463fdb38ed647b70460
BLAKE2b-256 e00af68239d704cba810839d10431fd1d92463aad5ab07a7987628b42bd62473

See more details on using hashes here.

File details

Details for the file compendium-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: compendium-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 26.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for compendium-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 caa32b66e962b0ca127ae1efc602829e5075ee64bee5b7a7f19a8c0fc91999ba
MD5 b6bc1b314a41a29a268a5621a41f1cb4
BLAKE2b-256 1ecb7e01a5cdb64ae58aa95662e10ab0e3c841d9bb6b226bafe1e7a3f9f9b51e

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