API Documentation

configurer module

class configurer.Component(config_manager, namespace=None)

A component creates an option group that all live in the same config namespace and get accessed together.

Parameters:
  • config_manager (ConfigManager) – Config manager pool to read options from.
  • namespace (list(str), optional) – Namespace that the compnent should be searched in.
get(name, default=NO_VALUE)

Get a raw value from the config manager pool.

Managing parsers, validations etc are all part of the Option and so calling get() directly will not invoke that logic. It is therefore recommended that users use the option accessor which will call this function.

Parameters:
  • name (str) – The name of the option to fetch.
  • default – A default value to return if not found.
class configurer.ConfigManager(readers)
get(name, namespace=None, default=NO_VALUE)
class configurer.Option(name, parser=None, validator=None, default=NO_VALUE, doc=None)

A defined configuration option.

Parameters:
  • name (str) – The name of the option that will be looked up.
  • parser – Function to parse the config value.
  • default – A default value to return if not found.
  • validator – Validation functions to run on the returned config value.
  • doc (str, Optional) – An explanatory string to add to any documentation.
name

The option identifier for the Option.

Returns:The name of the Option
Return type:str
parse(value)

Parse a value that will be returned according to the option spec.

Parameters:value – The value returned by the config option pool.
Returns:The value that should be returned to the config pool.
validate(value)

Validate a value against the validators stored in the Option.

Parameters:value – The value that should be validated.
Raises:configurer.ValidationError – On validation failure.
exception configurer.ConfigurerError

Base Exception class for all Exceptions defined in configurer.

exception configurer.ValidationError

An exception that is raised when a option vallue fails validation.

configurer.parsers module

configurer.parsers.Boolean(value)
configurer.parsers.List(parser, delimiter=', ')
configurer.parsers.Or(*parsers)

configurer.readers module

class configurer.readers.ConfigReader

Base class for implementing a Reader.

get(name, namespace=None)

Retrieve a value from a configuration source.

Parameters:
  • name (str) – The name of the value to retrieve.
  • namespace (list(str), Optional) – Namespace to retrieve option from.

configurer.validators module

class configurer.validators.Validator

Base validator class.

allow_no_value = False
class configurer.validators.ValidatorGroup(*validators)
allow_no_value = True
chain(option, validator, value)

Call another validator from an existing validator.

Parameters:
  • option (Option) – The option that is being processed.
  • validator (Validator) – The validator to call
  • value – The value to pass to the validator.
Raises:

ValidationError – When Validation fails for the value.

class configurer.validators.And(*validators)

Validate that all attached validators pass the test.

Parameters:validators (Validator) – The validators to assert against the value.
class configurer.validators.Or(*validators)

Validate that any one of the attached validators pass the test.

Parameters:validators (Validator) – The validators to assert against the value.
class configurer.validators.Not(*validators)

Invert the validation result to assert the result.

Parameters:validators (Validator) – The validators to assert against the value.
class configurer.validators.Required

Assert that the option is specified in the config values.

allow_no_value = True
class configurer.validators.GreaterThan(value)
class configurer.validators.LowerThan(value)
class configurer.validators.Regex(pattern, flags=0)

Assert that the value matches a regular expression.

Parameters:
  • pattern (str) – The regular expression to test exists.
  • flags (int) – flags to pass to the regular expression compilation.