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:
objectClass-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:
- Return type:
- 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:
- 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")
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:
- Returns:
Dict containing configuration data, or empty dict if file doesn’t exist
- Raises:
ImportError – If PyYAML is not installed
ValueError – If file exists but contains invalid YAML
Example
>>> config = load_config("app.yaml") >>> llm_settings = config.get("llm", {}) >>> model = llm_settings.get("model", "gpt-4o")