cliche.config — Reading configurations

class cliche.config.ConfigDict

Almost the same to the built-in dict except it raises ConfigKeyError instead of KeyError with finer error message.

exception cliche.config.ConfigKeyError

The exception raised when there’s no such configured key, that is a subtype of built-in KeyError.

cliche.config.read_config(filename)

Read Cliche app configuration from the given filename.

config = read_config(filename='dev.cfg.yml')

Note that it takes only one keyword argument at a time. All parameters are mutually exclusive for each other.

Parameters:filename (pathlib.Path) – read config from a filename of yaml or python source code
Returns:the parsed dictionary with uppercase keys
Return type:ConfigDict
cliche.config.read_config_from_python(*, string=None, file=None, filename=None)

Read Cliche app configuration from Python code i.e. Flask-style configuration:

config = read_config_from_python(filename='dev.cfg.py')

Note that it takes only one keyword argument at a time. All parameters are mutually exclusive for each other.

Parameters:
  • string (str) – read config from a python source code string
  • file – read config from a file object of python source code
  • filename (pathlib.Path) – read config from a filename of python source code
Returns:

the parsed dictionary with uppercase keys

Return type:

collections.abc.Mapping

cliche.config.read_config_from_yaml(*, string=None, file=None, filename=None)

Read Cliche app configuration from YAML.

config = read_config_from_yaml(filename='dev.cfg.yml')

Note that it takes only one keyword argument at a time. All parameters are mutually exclusive for each other.

Parameters:
  • string (str) – read config from a yaml string
  • file – read config from a file object of yaml
  • filename (pathlib.Path) – read config from a filename of yaml
Returns:

the parsed dictionary with uppercase keys

Return type:

ConfigDict