Reference

Main API

class maison.UserConfig(package_name, starting_path=None, source_files=None, schema=None, merge_configs=False)

Model the user configuration.

property discovered_paths: list[Path]

Return a list of the paths to the config sources found on the filesystem.

Returns:

a list of the paths to the config sources

property path: Path | list[Path] | None

Return the path to the selected config source.

Returns:

None is no config sources have been found, a list of the found config sources if merge_configs is True, or the path to the active config source if False

property schema: type[IsSchema] | None

Return the schema.

Returns:

the schema

validate(schema=None, use_schema_values=True)

Validate the configuration.

Warning

Using this method with use_schema_values set to True will cast values to whatever is defined in the schema. For example, for the following schema:

class Schema(ConfigSchema):

foo: str

Validating a config with:

{“foo”: 1}

Will result in:

{“foo”: “1”}

Parameters:
  • schema (Optional[type[IsSchema]]) – an optional class that follows the IsSchema protocol that defines the schema. This takes precedence over a schema provided at object instantiation.

  • use_schema_values (bool) – an optional boolean to indicate whether the result of passing the config through the schema should overwrite the existing config values, meaning values are cast to types defined in the schema as described above, and default values defined in the schema are used.

Return type:

dict[str, Union[str, int, float, bool, None, ConfigValues]]

Returns:

the config values

Raises:

NoSchemaError – when validation is attempted but no schema has been provided

property values: dict[str, str | int | float | bool | None | ConfigValues]

Return the user’s configuration values.

Returns:

the user’s configuration values

Exceptions

Module to define custom errors.

exception maison.errors.BadTomlError

Raised when loading from an invalid toml source is attempted.

exception maison.errors.NoSchemaError

Raised when validation is attempted but no schema has been provided.

exception maison.errors.UnsupportedConfigError

Raised when a config is attempted to be parsed but no parser is registered for it.