Glorpen Config

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

Config framework for Your projects - with validation, interpolation and value normalization!

Features

You can:

  • create custom fields for custom data
  • define configuration schema inside Python app
  • convert configuration values to Python objects
  • validate configuration
  • use interpolation to fill config values
  • set default values

Loading data

glorpen.config.Config uses glorpen.config.loaders to allow loading data from different sources.

Loaders should accept:

  • path, filepath constructor argument
  • file-like object, fileobj constructor argument

Additionally you can just pass dict data to config with glorpen.config.Config.load_data() or glorpen.config.Config.finalize().

Interpolation

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

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

String interpolation currently can be used only with glorpen.config.fields.String fields.

Normalization and validation

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

logging: DEBUG

config.get("logging") would yield value 10 as is logging.DEBUG.

Additionally it will raise glorpen.config.exceptions.ValidationError if invalid level name is given.

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 adhere to same interpolation and normalization rules - each default value is denormalized and then passed to normalizers. That way complex object can still profit from config interpolation. There should not be any real impact on performance as it is done only once.

Indices and tables