Skip to content

pillar.config 🔗

ConfigLoader 🔗

ConfigLoader(
    default_config: Optional[Dict[str, Any]] = None,
    default_parsers: Optional[
        Dict[str, ConfigParser]
    ] = None,
)

Bases: LoggingMixin

Load and merge multiple config files from various locations.

Attributes:

Name Type Description
logger Logger
merger Merger

deepmerge merger

parsers Dict[str, ConfigParser]

loaded parses

config Dict[str, Any]

computed config

load_stack Dict[str, Dict[str, Any]]

loaded files and their respective config before merging. Because dictionaries are ordered this will also be in order of loading. The only only exception is if the same file is loaded multiple times (don't do that).

load_errors Dict[str, Dict[str, Any]]

errors encountered when loading files. If the same file is loaded multiple times, it will only have the latest error encountered.

Parameters:

Name Type Description Default
default_config Optional[Dict[str, Any]]

Set initial self.config to this.

None
default_parsers Optional[Dict[str, ConfigParser]]

Use these parsers instead of the DEFAULT_PARSERS.

None

critical 🔗

critical(msg: str, *args, **kwargs) -> None

Log a CRITICAL message

Something is on fire. We somehow caught it but we probably need to exit now. If we keep going more things may catch on fire.

In a larger system, someone is probably going to get paged over this. An end user is definitely going to get an error message, probably not even a useful one, just a HTTP 500.

debug 🔗

debug(msg: str, *args, **kwargs) -> None

Log a DEBUG message

Basic debug messages

error 🔗

error(msg: str, *args, **kwargs) -> None

Log an ERROR message

Something bad has happened but we caught it. We might be able to continue, but other things might start breaking. We can probably still safely exit.

In a larger system, this will likely cause a gentle alert to be placed somewhere. An end user might receive a useful error message (like a HTTP 4xx 5xx).

get_logger classmethod 🔗

get_logger(prefix: str = '') -> logging.Logger

Get a logging.Logger for this class

Parameters:

Name Type Description Default
prefix str

optional prefix for the logger name

''

info 🔗

info(msg: str, *args, **kwargs) -> None

Log an INFO message

Print something to the screen/logfile so we know what is happening

load_config 🔗

load_config(
    path: Union[str, Path], *, suppress_errors: bool = False
) -> None

Load a given config path.

The loaded config will be merged into self.config. The actual config loaded will also be stored in self.load_stack[path]. Any errors during loading will be stored in self.load_errors[path].

Parameters:

Name Type Description Default
path Union[str, Path]

Path to try load from. Can include scheme (e.g. file://config/dev.json)

required
suppress_errors bool

Prevent errors from being thrown while loading the config. This does not affect errors being stored in self.load_errors.

False

Raises:

Type Description
ValueError

Unsupported path scheme

vdebug 🔗

vdebug(msg: str, *args, **kwargs) -> None

Log a Verbose Debug (VDEBUG) message.

More than debug, less than everything.

vvdebug 🔗

vvdebug(msg: str, *args, **kwargs) -> None

Log a Very Verbose Debug (VVDEBUG) message.

When you're tired of finding the bug and want to log everything.

warning 🔗

warning(msg: str, *args, **kwargs) -> None

Log a WARNING message

Something is wrong but we likely can recover or skip it without issue.

In a larger system this will likely just go to centralised logging.

ConfigParser 🔗

Base class for config loaders.

parse_content 🔗

parse_content(content: bytes) -> Any

Parse content into usable config.

Parameters:

Name Type Description Default
content bytes

Raw content to load from

required

JsonParser 🔗

Bases: ConfigParser

Config parser for JSON

If orjson is installed will use that for parsing. It can be installed using pillar[recommended].

parse_content 🔗

parse_content(content: bytes) -> Any

Parse config into a usable config.

See pillar.config.ConfigParser.parse_content.

YamlParser 🔗

Bases: ConfigParser

Config parser for YAML

parse_content 🔗

parse_content(content: bytes) -> Any

Parse config into a usable config.

See pillar.config.ConfigParser.parse_content.