pycnfg

Flexible Python configurations.


Keywords
configuration
License
Apache-2.0
Install
pip install pycnfg==0.0.2

Documentation

Pycnfg logo

Flexible Python configurations.

Build Status PyPi version PyPI Status Docs Telegram

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.

Logic

For details, please refer to Concepts.

Installation

PyPi PyPi version PyPI Status

pip install pycnfg
Development installation (tests and docs)

pip install pycnfg[dev]

Docker Docker Pulls

docker run -it nizaevka/pycnfg

Pycnfg is tested on: Python 3.6+.

Docs

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. License