cfgrw package¶
Subpackages¶
Module contents¶
Python library for reading configuration properties from files and environment variables.
- class cfgrw.CFGRW(conf_file=None)[source]¶
Bases:
objectReader for configuration properties from files and environment variables.
- read(props: list, opts={}) dict[source]¶
Read the values of a list of properties.
When a configuration file is set, properties are read from it first. Any properties absent from the file are looked up as environment variables when
prefixis provided inopts. When no configuration file is set, all properties are read from environment variables.Properties not found in any source are silently omitted from the result.
- Parameters:
props (list[str]) – Property names to read.
opts (dict) –
Reader options. Recognised keys:
section(str) — section name, required for INI files.prefix(str) — environment variable prefix, required for env var reads and env var fallback.
- Returns:
Mapping of property names to their values for all found properties.
- Return type:
dict
- cfgrw.CONF_FORMATS = {'ini': {'ext': ['.ini'], 'read_fn': <function read_values>}, 'json': {'ext': ['.json'], 'read_fn': <function read_values>}, 'xml': {'ext': ['.xml'], 'read_fn': <function read_values>}, 'yaml': {'ext': ['.yaml', '.yml'], 'read_fn': <function read_values>}}¶
dict: Supported configuration formats mapped to their file extensions and reader functions.
- cfgrw.JINJA_EXT = '.j2'¶
str: File extension suffix that marks a Jinja2 template.