API

Cascading configuration from the CLI and config files.

class cascade_config.CascadeConfig(validation_schema=None, none_overrides_value=False)

Cascading configuration.

Parameters
  • validation_schema (str, path-like, dict, or cascade_config.ValidationSchema, optional) – JSON Schema to validate fully cascaded configuration

  • none_overrides_value (bool) – If True, a None value overrides a not-None value from the previous configuration. If False, None values will never override not-None values.

Examples

>>> cascade_conf = CascadeConfig(validation_schema="config_schema.json")
>>> cascade_conf.add_json("config_default.json")
>>> cascade_conf.add_json("config_user.json")
>>> config = cascade_conf.parse()
property validation_schema

JSON Schema to validate fully cascaded configuration.

add_dict(*args, **kwargs)

Add dictionary configuration source to source list. *args and **kwargs are passed to cascade_config.DictConfigSource().

add_argumentparser(*args, **kwargs)

Add argumentparser configuration source to source list. *args and **kwargs are passed to cascade_config.ArgumentParserConfigSource().

add_namespace(*args, **kwargs)

Add argparse Namespace configuration source to source list. *args and **kwargs are passed to cascade_config.NamespaceConfigSource().

add_json(*args, **kwargs)

Add JSON configuration source to source list. *args and **kwargs are passed to cascade_config.JSONConfigSource().

parse()Dict

Parse all sources, cascade, validate, and return cascaded configuration.

class cascade_config.DictConfigSource(source, validation_schema=None, subkey=None)

Initialize a single configuration source.

Parameters
  • source (str, path-like, dict, argparse.ArgumentParser) – source for the configuration, either a dictionary, path to a file, or argument parser.

  • validation_schema (str, path-like, dict, or cascade_config.ValidationSchema, optional) – JSON Schema to validate single configuration

  • subkey (str) – adds the configuration to a subkey of the final cascased configuration; e.g. specifying a subkey “user” for a configuration source, would add it under the key “user” in the cascaded configuration, instead of updating the root of the existing configuration

load()

load the configuration from the source and return it as a dictionary

class cascade_config.JSONConfigSource(source, validation_schema=None, subkey=None)

Initialize a single configuration source.

Parameters
  • source (str, path-like, dict, argparse.ArgumentParser) – source for the configuration, either a dictionary, path to a file, or argument parser.

  • validation_schema (str, path-like, dict, or cascade_config.ValidationSchema, optional) – JSON Schema to validate single configuration

  • subkey (str) – adds the configuration to a subkey of the final cascased configuration; e.g. specifying a subkey “user” for a configuration source, would add it under the key “user” in the cascaded configuration, instead of updating the root of the existing configuration

load()

load the configuration from the source and return it as a dictionary

class cascade_config.ArgumentParserConfigSource(source, validation_schema=None, subkey=None)

Initialize a single configuration source.

Parameters
  • source (str, path-like, dict, argparse.ArgumentParser) – source for the configuration, either a dictionary, path to a file, or argument parser.

  • validation_schema (str, path-like, dict, or cascade_config.ValidationSchema, optional) – JSON Schema to validate single configuration

  • subkey (str) – adds the configuration to a subkey of the final cascased configuration; e.g. specifying a subkey “user” for a configuration source, would add it under the key “user” in the cascaded configuration, instead of updating the root of the existing configuration

load()

load the configuration from the source and return it as a dictionary

class cascade_config.NamespaceConfigSource(source, validation_schema=None, subkey=None)

Initialize a single configuration source.

Parameters
  • source (str, path-like, dict, argparse.ArgumentParser) – source for the configuration, either a dictionary, path to a file, or argument parser.

  • validation_schema (str, path-like, dict, or cascade_config.ValidationSchema, optional) – JSON Schema to validate single configuration

  • subkey (str) – adds the configuration to a subkey of the final cascased configuration; e.g. specifying a subkey “user” for a configuration source, would add it under the key “user” in the cascaded configuration, instead of updating the root of the existing configuration

load()

load the configuration from the source and return it as a dictionary

class cascade_config.ValidationSchema(source)

ValidationSchema.

classmethod from_object(obj)

Return ValidationSchema from str, path-like, dict, or ValidationSchema.

load()Dict

Load validation schema.