foca.config package
Submodules
foca.config.config_parser module
Parser for YAML-based app configuration.
- class foca.config.config_parser.ConfigParser(config_file: Path | None = None, custom_config_model: str | None = None, format_logs: bool = True)
Bases:
object
Parse FOCA config files.
- Parameters:
config_file – Path to config file in YAML format.
custom_config_model – Path to model to be used for custom config parameter validation, supplied in “dot notation”, e.g.,
myapp.config.models.CustomConfig`, where ``CustomConfig
is the actual importable name of a pydantic model for your custom configuration, deriving fromBaseModel
. FOCA will attempt to instantiate the model with the values passed to thecustom
section in the application’s configuration, if present. Wherever possible, make sure that default values are supplied for each config parameters, so as to make it easier for others to write/modify their app configuration.format_logs – Whether log formatting should be configured.
- config_file
Path to config file in YAML format.
- custom_config_model
Path to model to be used for custom config parameter validation, supplied in “dot notation”, e.g.,
myapp.config.models.CustomConfig`, where ``CustomConfig
is the actual importable name of a pydantic model for your custom configuration, deriving fromBaseModel
. FOCA will attempt to instantiate the model with the values passed to thecustom
section in the application’s configuration, if present. Wherever possible, make sure that default values are supplied for each config parameters, so as to make it easier for others to write/modify their app configuration.
- format_logs
Whether log formatting should be configured.
- static merge_yaml(*args: Path) Dict
Parse and merge a set of YAML files.
Merging is done iteratively, from the first, second to the n-th argument. Dictionary items are updated, not overwritten. For exact behavior cf. https://github.com/mewwts/addict.
- Parameters:
*args – One or more paths to YAML files.
- Returns:
Dictionary of merged YAML file contents, or
None
if no arguments have been supplied; if only a single YAML file path is provided, no merging is done.
- parse_custom_config(model: str) BaseModel
Parse custom configuration and validate against a model.
The method will attempt to instantiate the model with the parameters provided in the application configuration’s
custom
section, if provided. Any required configuration parameters for which no defaults are provided in the model indeed will have to be listed in such a section.- Parameters:
model – Path to model to be used for configuration validation, supplied in “dot notation”, e.g.,
myapp.config.models.CustomConfig`, where ``CustomConfig
is the actual importable name of a pydantic model for your custom configuration, deriving fromBaseModel
.- Returns:
Custom configuration model instantiated with the parameters listed in the app configuration’s
custom
.
- static parse_yaml(conf: Path) Dict
Parse YAML file.
- Parameters:
conf – Path to YAML file.
- Returns:
Dictionary of conf contents.
- Raises:
OSError – File cannot be accessed.
ValueError – File contents cannot be parsed.