SubConfigKeyTransformer#
- class tollan.config.SubConfigKeyTransformer[source]#
Bases:
GenericMixin for handlers that extract a subkey from runtime config.
This provides a convenient pattern for handlers that manage a specific section of the runtime config identified by a key.
The subconfig_key is automatically inferred from Literal type parameters.
- Type Parameters:
- KeyT: Literal type specifying the subconfig key
(e.g., Literal[“database”])
Example
>>> from typing import Literal >>> from pydantic import BaseModel >>> from tollan.config import ( ... ConfigHandler, ... SubConfigKeyTransformer, ... RuntimeContext, ... ) >>> >>> class DatabaseConfig(BaseModel): ... url: str >>> >>> class DatabaseHandler( ... SubConfigKeyTransformer[Literal["database"]], ... ConfigHandler[DatabaseConfig] ... ): ... pass >>> >>> rc = RuntimeContext( ... config_sources=[ ... { ... "format": "dict", ... "source": {"database": {"url": "postgresql://localhost"}}, ... "order": 0, ... } ... ] ... ) >>> handler = DatabaseHandler(rc) >>> handler.config.url 'postgresql://localhost'
Methods Summary
prepare_config_data(runtime_config)Extract subconfig data by key.
prepare_runtime_config_data(config_data)Wrap config data under subconfig key.
Methods Documentation
- classmethod prepare_config_data(runtime_config: RuntimeConfig) dict[source]#
Extract subconfig data by key.
- Parameters:
runtime_config (RuntimeConfig) – RuntimeConfig model instance
- Returns:
Subconfig data dict
- Return type: