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'