Configuration Management¶
- class distconfig.config.Config(data)¶
Read only mapping-like for holding configuration.
Note: At the opposite of ConfigParser.RawConfigParser in stdlib, methods like get_<type> in this class do not coerse, instead the use case is type assertion, i.e. When a user call Config.get_int on a key where the value is a string e.g. ‘2’, the call will fail with a TypeError.
- get(path, default=None, type_=None)¶
Same as dict.get(k[,d]) with an extra argument type_ that assert type matching if given.
path argument can be in the form ‘key1/key2/key3’ as a shortcut for doing config['key1']['key2']['key3']. In case a key have a / in it, we can escape it like so ‘key1/key2/key3’ this will be translated to config['key1/key2']['key3']
Parameters: - path – path expression e.g. ‘key1/key2/key3’
- default – default value to return when key is missing, in case it’s supplied default with type_, default must be of of type type_, default: None.
- type – Python type to validate returned value, default: None.
Returns: the value of the requested path as a string.
Raises: - TypeError – if path value is not of type type_.
- KeyError – if path doesn’t exist and default is set to distconfig.config.UNDEFINED.
- get_boolean(path, default=<object object at 0x7f08535902c0>)¶
Get path value as boolean.
Parameters: - path – path expression e.g. ‘key1.key2.key3’
- default – default value to return when key is missing, if supplied default must be of type boolean, default: UNDEFINED.
Returns: the value of the requested path as a Boolean.
Raises: - TypeError – if path value is not of type type_.
- KeyError – if path doesn’t exist and no default was given.
- get_bytes(path, default=<object object at 0x7f08535902c0>)¶
Get path value as bytes.
Parameters: - path – path expression e.g. ‘key1.key2.key3’
- default – default value to return when key is missing, if supplied default must be of type bytes, default: UNDEFINED.
Returns: the value of the requested path as a Unicode.
Raises: - TypeError – if path value is not of type type_.
- KeyError – if path doesn’t exist and no default was given.
- get_config(path, default=<object object at 0x7f08535902c0>)¶
Get path value as Config.
Parameters: - path – path expression e.g. ‘key1.key2.key3’
- default – default value to return when key is missing, if supplied default must be of type dict, default: UNDEFINED.
Returns: the value of the requested path as a Config instance.
Raises: - TypeError – if path value is not of type type_.
- KeyError – if path doesn’t exist and no default was given.
- get_float(path, default=<object object at 0x7f08535902c0>)¶
Get path value as float.
Parameters: - path – path expression e.g. ‘key1.key2.key3’
- default – default value to return when key is missing, if supplied default must be of type float, default: UNDEFINED.
Returns: the value of the requested path as a Float.
Raises: - TypeError – if path value is not of type type_.
- KeyError – if path doesn’t exist and no default was given.
- get_int(path, default=<object object at 0x7f08535902c0>)¶
Get path value as integer.
Parameters: - path – path expression e.g. ‘key1.key2.key3’
- default – default value to return when key is missing, if supplied default must be of type integer, default: UNDEFINED.
Returns: the value of the requested path as a Integer.
Raises: - TypeError – if path value is not of type type_.
- KeyError – if path doesn’t exist and no default was given.
- get_unicode(path, default=<object object at 0x7f08535902c0>)¶
Get path value as unicode.
Parameters: - path – path expression e.g. ‘key1.key2.key3’
- default – default value to return when key is missing, if supplied default must be of type unicode, default: UNDEFINED.
Returns: the value of the requested path as a Unicode.
Raises: - TypeError – if path value is not of type type_.
- KeyError – if path doesn’t exist and no default was given.