Config Loader

Configuration loader utilities for Arshai framework.

Provides optional configuration loading without imposing patterns on developers. Configuration files are optional - functions return empty dict if file doesn’t exist.

Classes

class arshai.config.config_loader.ConfigLoader(config_path)[source]

Bases: object

Class-based configuration loader.

Provides dot-notation access to configuration values with defaults. Configuration files are optional - loader works with empty config if file doesn’t exist.

Example

>>> loader = ConfigLoader("app.yaml")
>>> model = loader.get("llm.model", "gpt-4o")
>>> temperature = loader.get("llm.temperature", 0.7)
__init__(config_path)[source]

Initialize configuration loader.

Parameters:

config_path (str) – Path to YAML configuration file

Note

If config file doesn’t exist, loader will work with empty configuration. This is not considered an error - allows for environment-only configuration.

get(key, default=None)[source]

Get configuration value using dot notation.

Parameters:
  • key (str) – Configuration key using dot notation (e.g., “llm.model”)

  • default (Optional[Any]) – Default value if key is not found

Return type:

Any

Returns:

Configuration value or default

Example

>>> loader = ConfigLoader("app.yaml")
>>> model = loader.get("llm.model", "gpt-4o")
>>> nested_value = loader.get("database.redis.host", "localhost")
get_section(section)[source]

Get entire configuration section.

Parameters:

section (str) – Section name (top-level key)

Return type:

Dict[str, Any]

Returns:

Dictionary containing section data, or empty dict if section doesn’t exist

Example

>>> loader = ConfigLoader("app.yaml")
>>> llm_config = loader.get_section("llm")
>>> database_config = loader.get_section("database")
has_key(key)[source]

Check if configuration key exists.

Parameters:

key (str) – Configuration key using dot notation

Return type:

bool

Returns:

True if key exists, False otherwise

Example

>>> loader = ConfigLoader("app.yaml")
>>> if loader.has_key("llm.model"):
...     model = loader.get("llm.model")
get_all()[source]

Get all configuration data.

Return type:

Dict[str, Any]

Returns:

Complete configuration dictionary

Example

>>> loader = ConfigLoader("app.yaml")
>>> all_config = loader.get_all()
>>> print(f"Loaded sections: {list(all_config.keys())}")

Functions

arshai.config.config_loader.load_config(config_path)[source]

Load configuration from YAML file.

Parameters:

config_path (str) – Path to YAML configuration file

Return type:

Dict[str, Any]

Returns:

Dict containing configuration data, or empty dict if file doesn’t exist

Raises:

Example

>>> config = load_config("app.yaml")
>>> llm_settings = config.get("llm", {})
>>> model = llm_settings.get("model", "gpt-4o")