Configuration Introspectionο
Configuration introspection utilities for Confii.
This module provides utilities for querying and inspecting configuration structure, types, and values.
- confii.config_introspection.get_all_keys(config: Dict[str, Any], prefix: str = '') List[str][source]ο
Recursively get all keys from a configuration dictionary.
- Parameters:
config β Configuration dictionary
prefix β Optional prefix for nested keys (e.g., βdatabaseβ for nested keys)
- Returns:
List of dot-separated key paths
Example
>>> config = {"database": {"host": "localhost", "port": 5432}} >>> get_all_keys(config) ['database', 'database.host', 'database.port']
- confii.config_introspection.get_nested_value(config: Dict[str, Any], key_path: str, default: Any = None) Any[source]ο
Get a nested value from configuration using dot notation.
- Parameters:
config β Configuration dictionary
key_path β Dot-separated key path (e.g., βdatabase.hostβ)
default β Default value if key not found
- Returns:
Configuration value or default if not found
Example
>>> config = {"database": {"host": "localhost"}} >>> get_nested_value(config, "database.host") 'localhost' >>> get_nested_value(config, "database.port", default=5432) 5432
- confii.config_introspection.get_schema_info(config: Dict[str, Any], key_path: str = '') Dict[str, Any][source]ο
Get schema information for a configuration key or entire config.
- Parameters:
config β Configuration dictionary
key_path β Optional dot-separated key path. If empty, returns schema for entire config.
- Returns:
Dictionary with schema information (type, required, nested keys, etc.)
Example
>>> config = {"database": {"host": "localhost", "port": 5432}} >>> schema = get_schema_info(config, "database") >>> schema["type"] # 'dict' >>> schema["keys"] # ['host', 'port']
- confii.config_introspection.has_key(config: Dict[str, Any], key_path: str) bool[source]ο
Check if a configuration key exists.
- Parameters:
config β Configuration dictionary
key_path β Dot-separated key path (e.g., βdatabase.hostβ)
- Returns:
True if key exists, False otherwise
Example
>>> config = {"database": {"host": "localhost"}} >>> has_key(config, "database.host") True >>> has_key(config, "database.port") False
- confii.config_introspection.infer_type(value: Any) str[source]ο
Infer the type name of a configuration value.
- Parameters:
value β Configuration value
- Returns:
Type name as string (e.g., βstrβ, βintβ, βdictβ, βlistβ)
Example
>>> infer_type("hello") 'str' >>> infer_type(42) 'int' >>> infer_type({"key": "value"}) 'dict'