Main Package File

fejao_config_parser.main

Main entry point for the fejao_config_parser package.

This module provides the my_config function, which is the primary interface for loading and resolving configuration values from multiple sources. It orchestrates the parsing process and returns a configured GetConfig instance with resolved values accessible as attributes.

Functions:

my_config

my_config(config: list, config_file_path: str = None, description: str = None, debug: bool = None) -> None

Load and resolve configuration values from multiple sources.

This function validates the configuration schema, loads values from defaults, optional config files, environment variables, and terminal arguments, then resolves final values based on precedence.

The precedence order for configuration values is as follows
  1. Terminal arguments (highest precedence, if set and not the default)
  2. Environment variables (if set)
  3. Configuration file values (if a config file is provided and values are set)
  4. Default values (lowest precedence)
Parameters:
  • config (list) –

    List of configuration dictionaries defining each item.

  • config_file_path (str, default: None ) –

    Path to a configuration file.

  • description (str, default: None ) –

    Description for CLI help text.

  • debug (bool, default: None ) –

    Enable debug output showing value resolution.

Returns:
  • GetConfig( None ) –

    Instance with resolved configuration values as attributes.

Raises:
  • ValueError –

    If the config parameter is not a list.

Example

config = [ ... {"name": "debug", "type": "bool", "default": False}, ... {"name": "port", "type": "int", "default": 8080} ... ] result = my_config(config=config, debug=True) print(result.debug, result.port) False 8080

Source code in fejao_config_parser/main.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def my_config(
    config: list,
    config_file_path: str = None,
    description: str = None,
    debug: bool = None
) -> None:
    """Load and resolve configuration values from multiple sources.

    This function validates the configuration schema, loads values from defaults,
    optional config files, environment variables, and terminal arguments, then
    resolves final values based on precedence.

    The precedence order for configuration values is as follows:
        1. Terminal arguments (highest precedence, if set and not the default)
        2. Environment variables (if set)
        3. Configuration file values (if a config file is provided and values are set)
        4. Default values (lowest precedence)

    Args:
        config (list): List of configuration dictionaries defining each item.
        config_file_path (str, optional): Path to a configuration file.
        description (str, optional): Description for CLI help text.
        debug (bool, optional): Enable debug output showing value resolution.

    Returns:
        GetConfig: Instance with resolved configuration values as attributes.

    Raises:
        ValueError: If the config parameter is not a list.

    Example:
        >>> config = [
        ...     {"name": "debug", "type": "bool", "default": False},
        ...     {"name": "port", "type": "int", "default": 8080}
        ... ]
        >>> result = my_config(config=config, debug=True)
        >>> print(result.debug, result.port)
        False 8080
    """
    if not isinstance(config, list):
        raise ValueError(
            "\n\nError parsing the configuration. "
            "The variable 'config' must be a list of dictionaries. "
            "Please refer to the documentation for more details.\n"
        )

    get_config = GetConfig(config=config, config_file_path=config_file_path, description=description, debug=debug)

    return get_config