core.json_config module

Proxy to abstract access to JSON configuration and gracefully handle missing keys.

class core.json_config.JSONConfiguration(filename, default=None, warn=True)[source]

Bases: object

Proxy for JSON-based configuration files.

static from_text(text)[source]

Create a JSONConfiguration object from a string.

get(path, default=None)[source]

Retrieves a value from the configuration. Returns default if the path does not exist.

Parameters
  • path/-delimited path to the string.

  • default – value returned if path does not exist.

get_bool(path)[source]

Retrieves a value from the configuration. Returns False if the path does not exist.

Parameters

path/-delimited path to the string.

get_dict(path)[source]

Retrieves a value from the configuration. Returns an empty dictionary if the path does not exist.

Parameters

path/-delimited path to the string.

get_list(path)[source]

Retrieves a value from the configuration. Returns an empty list if the path does not exist.

Parameters

path/-delimited path to the string.

get_number(path)[source]

Retrieves a value from the configuration. Returns 0 if the path does not exist.

Parameters

path/-delimited path to the string.

get_string(path)[source]

Retrieves a value from the configuration. Returns an empty string if the path does not exist.

Parameters

path/-delimited path to the string.

get_value(path, default=None)[source]

Retrieves a value from the configuration. Returns default if the path does not exist.

Parameters
  • path/-delimited path to the string.

  • default – value returned if path does not exist.

has_value(path)[source]

Returns True if the path exists in the configuration.

save_data()[source]

Saves the data to the original JSON file. Has no effect if no filename was given during construction.

set_value(key, value)[source]

Writes a value to a key. Note: Arbitrary paths not supported - you must refresh entire key.

Parameters
  • key – the key to save the value under.

  • value – the value to save.