Package: pyaconf
pyaconf - yet another config library built around python dictionaryPyaconf is a config library that is built around python dictionary and supports dynamic python, json, yaml, and ini formats with inheritance.
It features:Features4 formats (pyaconf [python], yaml, json, ini) that can be layered on top of each other,dynamic pyaconf (python) format,includefeature that can layer combine the 4 formats hierarchically,“merge” capability that allows to override values by the topmost layer,jinja2 template substitution capability that can be injected at various layers of override and dictionary hierarchies,simple 3 function (load, merge, and dump) Python API, andcommand line utility that allows us to use all these features from the command lineNotesAll configs are json compatible dicts.Supports layered configs (inheritance) via__include__dict entry, for example, the following yaml config would read the dictionary defined from configboo.jsonand then will update it withuserandpasswordfrom this config:__include__:boo.jsonuser:romeopassword:romeoalphaIncludes may be used at any level and apply only to its layer.Simple API:load,dump, and for more advanced usemerge.Supports dynamic configs written in Python.pyaconf, for example:importosdefconfig():returndict(__include__=["secret.yml"],user="romeo",password=os.environ['PASSWORD'],database=dict(__include__="db.ini",),)Allows to output configs in.jsonand.yaml. Provides two shell scripts.Supports.iniinput format as understood by python'sconfigparser.Supports Jinji2 templates, you just need to add.j2or.jinji2extension to your config file and it will be processed by Jinji2. For example:user:{{username}}password = {{ password }}The dictionary that contains includes serves as a context for these includes. For template includes, the dictionary is passed as a context to the template processing. For non-template includes, the dictionary merges with the include. When all includes processed this way, they all merge together.__include__:[a.yaml.j2,b.yaml]x:1y:2Another example with template:# common.yaml.j2host:localuser:{{username}}password:{{password}}credentials:[{{password}},{{username}}]# devel.yaml__include__:common.yaml.j2username:Donaldpassword:Trumpoffice:113D# pyaconf_render -f json devel.yaml{"credentials":["Trump","Donald"],"host":"local","password":"Trump","user":"Donald"}APIloaddefload(src,*,format='auto',path=None,context={}):""" loads a dict that may include special keyword '__include__' at multiple levels,and resolves these includes and returns a dict without includes. It can also read the input dict from a filesrc -- dict|Mapping, FILE|io.StringIO(s), pathlib.Path|strformat -- 'auto' | 'pyaconf' | 'json' | 'yaml' | 'ini'path -- is used only when src doesn't contain path info, it is used for error messages and resolve relative include pathscontext -- is a dict that is used as context for template rendering if src is a template"""dumpdefdump(x,dst=sys.stdout,*,format='auto'):""" Dumps resolved (without includes) config in json or yaml format. It doesn't preserve comments either.x -- dict|Mappingdst -- FILE|io.StringIO(s), pathlib.Path|strformat -- 'auto' | 'json' | 'yaml'"""mergedefmerge(xs):""" merges the list of dicts (that dont contain includes) and returns a new dictwhere the values of the first dict are updated recursively by the values of the second dict.xs -- a list of dicts"""Scriptspyaconf_render -- loads and merges multiple configs and renders the result in json or yaml formatLicenseOSI Approved 3 clause BSD LicensePrerequisitesPython 3.7+InstallationIf prerequisites are met, you can installpyaconflike any other Python package, using pip to download it from PyPI:$ pip install pyaconfor usingsetup.pyif you have downloaded the source package locally:$ python setup.py build
$ sudo python setup.py install