Flexible Python configurations.
Project description
Pycnfg is a tool to execute Python-based configuration.
- Pure Python.
- Flexible.
It offers unified patten to create arbitrary Python objects pipeline-wise. That naturally allows to control all parameters via single file.
For details, please refer to Concepts.
Installation
PyPi
pip install pycnfg
Development installation (tests and docs)
pip install pycnfg[dev]
Docker
docker run -it nizaevka/pycnfg
Pycnfg is tested on: Python 3.6+.
Docs
Getting started
"""Configuration example to produce object."""
import pycnfg
class CustomProducer(pycnfg.Producer):
"""Specify custom methods to produce object."""
def __init__(self, objects, oid):
# Mandatory.
super().__init__(objects, oid)
def set(self, obj, key, val=42):
obj[key] = val
return obj
def print(self, obj, key='a'):
print(obj[key])
return obj
def method_id(self, obj, *args, **kwargs):
# Some logic..
return obj
# Configuration.
# Set `init` object state {'a': 7}.
# Set `producer` class CustomProducer.
# Set `steps` to execute.
CNFG = {
'section_1': {
'conf_1': {
'init': {'a': 7},
'producer': CustomProducer,
'steps': [
('set', {'key': 'b', 'val': 42}),
('print', {}),
('print', {'key': 'b'}),
('method_id', {}),
],
},
# 'conf_2': {...}
}
# 'section_2': {...}
}
if __name__ == '__main__':
# Execute configuration(s) in priority.
objects = pycnfg.run(CNFG)
# => 7
# => 42
# Storage for produced object(s).
print(objects['section_1__conf_1'])
# => {'a': 7, 'b': 42}
see docs for details ;)
Examples
Check examples folder.
Check also mlshell - a ML framework based on Pycnfg.
Contribution guide
License
Apache License, Version 2.0 LICENSE.
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
pycnfg-0.0.2.tar.gz
(20.4 kB
view hashes)
Built Distribution
pycnfg-0.0.2-py3-none-any.whl
(19.7 kB
view hashes)