API Reference /

registry.py

Local component registry for TuiML.

Provides the local algorithm/feature/preprocessor registry used by @classifier, @regressor, @transformer decorators across the library, plus the shared ComponentType enum and Registrable mixin.

Local component registration:

python
from tuiml.registry import registry
python
@registry.register("classifier")
class MyClassifier:
    pass
python
model = registry.create("MyClassifier", param=value)

Classes

ComponentType

class registry.ComponentType(Enum)

Types of components that can be registered.

Registrable

class registry.Registrable(ABC)

Base mixin for all registrable components.

Any class that wants to be registered in the hub should inherit from this.

Methods

get_component_info (cls) -> Dict[str, Any]

Return component metadata for registration.

Returns
info
dict
A dictionary containing component information.
get_parameter_schema (cls) -> Dict[str, Dict[str, Any]]

Return JSON Schema for component parameters.

Returns
schema
dict
A dictionary mapping parameter names to their schemas.

Registry

class registry.Registry

Local registry for TuiML components.

Provides discovery, registration, and instantiation of local components. Supports plugins from external packages.
python
>>> from tuiml.registry import registry
>>> # Register a custom algorithm
>>> @registry.register("classifier")
... class MyClassifier:
...     pass
>>> # List all classifiers
>>> registry.list(ComponentType.CLASSIFIER)
>>> # Get a component by name
>>> cls = registry.get("MyClassifier")

Methods

suppress_overwrite_warnings (self)

Temporarily silence the "already registered" overwrite warning.

Yields
None
The context within which overwrite warnings are suppressed.
register (self, component_type: Union[ComponentType, str], name: Optional[str]=None, tags: Optional[List[str]]=None, version: str='1.0.0', author: Optional[str]=None) -> Callable[..., Type]

Decorator to register a component in the hub.

Parameters
component_type
ComponentType or str
Type of component being registered.
name
str = None
Custom name for the component. Defaults to the class name.
tags
list of str = None
Tags for component discovery.
version
str = "1.0.0"
Component version string.
author
str = None
Name of the component author.
Returns
decorator
callable
A class decorator that registers the component.
register_class (self, cls: Type, component_type: ComponentType, name: Optional[str]=None) -> None

Register a class directly (non-decorator usage).

Parameters
cls
Type
The class to register.
component_type
ComponentType
The type of component.
name
str = None
Custom name for the component.
unregister (self, name: str) -> bool

Remove a component from the registry.

Parameters
name
str
The name of the component to remove.
Returns
success
bool
True if the component was found and removed, False otherwise.
get (self, name: str) -> Type

Get a component class by name.

Parameters
name
str
The name of the component to retrieve.
Returns
cls
Type
The registered component class.
Raises
KeyError
If the component name is not found in the registry.
get_info (self, name: str) -> Dict[str, Any]

Get component metadata by name.

Parameters
name
str
The name of the component.
Returns
info
dict
A dictionary containing component metadata.
create (self, name: str, **kwargs) -> Any

Create an instance of a component.

Parameters
name
str
The name of the component to instantiate.
**kwargs
Any
Arguments passed to the component's constructor.
Returns
instance
Any
An instance of the requested component.
list (self, component_type: Optional[ComponentType]=None, tags: Optional[List[str]]=None) -> List[Dict[str, Any]]

List components, optionally filtered by type or tags.

Parameters
component_type
ComponentType = None
Filter components by type.
tags
list of str = None
Filter components by tags. Components must have ALL specified tags.
Returns
results
List[dict]
A list of component metadata dictionaries.
list_names (self, component_type: Optional[ComponentType]=None) -> List[str]

List component names, optionally filtered by type.

Parameters
component_type
ComponentType = None
Filter components by type.
Returns
names
List[str]
A list of registered component names.
add_hook (self, event: str, callback: Callable) -> None

Add a hook to be called on registry events.

Parameters
event
str
The event name ('on_register' or 'on_unregister').
callback
callable
The function to call. It will receive (class, info) as arguments.
Raises
ValueError
If the event name is unknown.
clear (self) -> None

Clear all registered components (mainly for testing).