Glorpen Config

https://travis-ci.org/glorpen/glorpen-config.svg?branch=master https://readthedocs.org/projects/glorpen-config/badge/?version=latest https://codecov.io/gh/glorpen/glorpen-config/branch/master/graph/badge.svg

Config framework for Your projects - with validation, interpolation and value normalization. It can even generate default config with help texts!

Features

You can:

  • define configuration schema inside Python app
  • convert configuration values to Python objects
  • validate user provided data
  • use interpolation to fill config values
  • generate example configuration with help text

How to load data

You can use Reader to read values from arbitrary source and then pass it to glorpen.config.Config:

from glorpen.config.translators.yaml import YamlReader
from glorpen.config import Config

config = Config(String())
config.get(YamlReader("example.yaml").read())

or with use of glorpen.config.Translator:

from glorpen.config.translators.yaml import YamlReader
from glorpen.config import Config, Translator

translator = Translator(Config(String()))
translator.read(YamlReader("example.yaml"))

glorpen.config.Config.get() accepts anything that is supported by underlying config schema so you can pass dict or custom objects.

Interpolation

You can reuse values from config with dotted notation, eg: {{ path.to.value }}.

project:
   path: "/tmp"
   cache_path: "{{ project.path }}/cache"

See field documentation to find where interpolation is supported.

Normalization and validation

Each field type has own normalization rules, eg. for glorpen.config.fields.log.LogLevel:

logging: DEBUG

config.get(data) would yield value 10 as in logging.DEBUG.

Additionally it will raise exception if invalid value is provided.

Optional and default values

Each field can have default value. If no value is given in config but default one is set, it will be used instead.

Default values should be already Python values, eg. int, str, objects.

Indices and tables