Skip to content

Base

fyt.registries.base

ComponentRegistry

Bases: Generic[T]

Generic base registry for component factories.

Each subclass maintains its own _registry mapping string keys to factory callables. The register decorator adds entries, and create looks them up.

Subclasses must declare their own _registry class variable (enforced by __init_subclass__).

Example::

class MyRegistry(ComponentRegistry[BaseEstimator]):
    _registry: ClassVar[dict[str, Callable[..., BaseEstimator | None]]] = {}


@MyRegistry.register("my_strategy")
def _create_my(**kwargs) -> BaseEstimator:
    return MyEstimator(**kwargs)


estimator = MyRegistry.create("my_strategy", n_estimators=100)

__init_subclass__(**kwargs)

Ensure every subclass gets its own _registry dict.

create(key, **kwargs) classmethod

Look up key in the registry and call the factory.

Parameters:

Name Type Description Default
key str | Enum

Strategy identifier — a string or an enum whose .value is used.

required
**kwargs Any

Forwarded to the registered factory callable.

{}

Returns:

Type Description
T | None

A new component instance, or None for passthrough.

Raises:

Type Description
ValueError

If key is not registered and is not passthrough.

get_available() classmethod

Return the list of registered keys (excluding passthrough).

Returns:

Type Description
list[str]

Sorted list of registered string keys.

normalize_key(key) classmethod

Convert an enum or string key to a canonical lowercase string.

Parameters:

Name Type Description Default
key str | Enum

Raw key value.

required

Returns:

Type Description
str

Normalized lowercase string.

register(key) classmethod

Decorator to register a factory function or class under key.

When decorating a class, it is automatically wrapped so that create(key, **kwargs) calls TheClass(**kwargs).

Parameters:

Name Type Description Default
key str

String identifier for the component (e.g. "mean").

required

Returns:

Type Description
Callable

Decorator that stores the target in the registry.