rlightning.utils.registry.registry¶
Registry class for component registration and discovery.
This module provides the Registry class for dynamically registering and retrieving classes or functions by name, enabling plugin-style architectures.
- class rlightning.utils.registry.registry.Registry(name: str)[source]¶
Bases:
objectA registry for mapping string names to classes or functions.
Provides a decorator-based API for registering components and retrieving them by name at runtime.
- name¶
The name of this registry.
- module_dict¶
Dictionary mapping names to registered items.
Example
>>> MODELS = Registry("models") >>> @MODELS.register("my_model") ... class MyModel: ... pass >>> model_cls = MODELS.get("my_model")
- get(key: str) Any[source]¶
Get a registered class or function by name.
- Parameters:
key – The name of the registered item.
- Returns:
The registered class or function.
- Raises:
KeyError – If the key is not found in the registry.
- register(name: str | None = None) Callable[[T], T][source]¶
Register a module with the registry.
A decorator for registering classes or functions.
- Parameters:
name – The name to register the module with. If None, the module’s __name__ will be used.
- Returns:
Decorator function that registers and returns the class.
- Raises:
KeyError – If the name is already registered.