lenskit.pipeline.components#

Definition of the component interfaces.

Attributes#

PipelineFunction

Pure-function interface for pipeline functions.

Classes#

ComponentInput

Representation of a component input slot.

ComponentConstructor

Protocol for component constructors.

Component

Base class for pipeline component objects. Any component that is not just a

PlaceholderConfig

Configuration for the placeholder component.

Placeholder

Simple no-op component to use as a placeholder in partial pipelines.

Functions#

component_inputs(component, *[, warn_on_missing, ...])

component_return_type(component)

fallback_on_none(primary, fallback)

Fallback to a second component if the primary input is None.

is_component_class(obj)

Check if the provided object is a component class.

Module Contents#

type lenskit.pipeline.components.PipelineFunction = Callable[..., COut]#

Pure-function interface for pipeline functions.

class lenskit.pipeline.components.ComponentInput#

Representation of a component input slot.

name: str#
type: ComponentInput.type | None = None#
is_lazy: bool = False#
accepts_none: bool = False#
has_default: bool = False#
class lenskit.pipeline.components.ComponentConstructor[CFG, COut]#

Bases: Protocol

Protocol for component constructors.

__call__(config=None)#
Parameters:

config (CFG | None)

Return type:

Component[COut]

config_class()#
Return type:

type[CFG] | None

validate_config(data=None)#
Parameters:

data (Any)

Return type:

CFG | None

class lenskit.pipeline.components.Component[COut](config=None, **kwargs)#

Bases: abc.ABC

Base class for pipeline component objects. Any component that is not just a function should extend this class.

Pipeline components support configuration (e.g., hyperparameters or random seeds) through Pydantic models or Python dataclasses; see Configuring Components for further details. If the pipeline’s configuration class is C, it has the following:

  1. The configuration is exposed through an instance variable config.

  2. The constructor accepts the configuration object as its first parameter, also named config, and saves this in the member variable.

The base class constructor handles both of these, so long as you declare the type of the config member:

class MyComponent(Component):
    config: MyComponentConfig

    ...

If you do not declare a config attribute, the base class will assume the pipeline uses no configuration.

To work as components, derived classes also need to implement a __call__ method to perform their operations.

Parameters:
  • config (object | None) – The configuration object. If None, the configuration class will be instantiated with kwargs.

  • kwargs (Any)

Stability:
Full (see Stability Levels).
config: Any = None#

The component configuration object. Component classes that support configuration must redefine this attribute with their specific configuration class type, which can be a Python dataclass or a Pydantic model class.

classmethod __init_subclass__(**kwargs)#
Parameters:

kwargs (Any)

classmethod config_class(return_any=False)#
Parameters:

return_any (bool)

Return type:

type | None

dump_config()#

Dump the configuration to JSON-serializable format.

Return type:

dict[str, pydantic.JsonValue]

classmethod validate_config(data=None)#

Validate and return a configuration object for this component.

Parameters:

data (Mapping[str, pydantic.JsonValue] | None)

Return type:

object | None

abstractmethod __call__(*args, **kwargs)#

Run the pipeline’s operation and produce a result. This is the key method for components to implement.

Parameters:
  • args (Ellipsis)

  • kwargs (Ellipsis)

Return type:

COut

__repr__()#
Return type:

str

class lenskit.pipeline.components.PlaceholderConfig#

Bases: pydantic.BaseModel

Configuration for the placeholder component.

class lenskit.pipeline.components.Placeholder(config=None, **kwargs)#

Bases: Component[Any]

Simple no-op component to use as a placeholder in partial pipelines.

Parameters:
  • config (object | None)

  • kwargs (Any)

config: PlaceholderConfig#

The component configuration object. Component classes that support configuration must redefine this attribute with their specific configuration class type, which can be a Python dataclass or a Pydantic model class.

abstractmethod __call__(**kwargs)#

Run the pipeline’s operation and produce a result. This is the key method for components to implement.

Parameters:

kwargs (Any)

Return type:

Any

lenskit.pipeline.components.component_inputs[COut](component, *, warn_on_missing=True, _warn_level=1)#
Parameters:
Return type:

dict[str, ComponentInput]

lenskit.pipeline.components.component_return_type[COut](component)#
Parameters:

component (Component[COut] | ComponentConstructor[Any, COut] | PipelineFunction[COut])

Return type:

type[COut] | None

lenskit.pipeline.components.fallback_on_none[T](primary, fallback)#

Fallback to a second component if the primary input is None.

Stability:
Caller (see Stability Levels).
Parameters:
Return type:

T

lenskit.pipeline.components.is_component_class(obj)#

Check if the provided object is a component class.

Parameters:

obj (Any)

Return type:

bool

Exported Aliases#

exception lenskit.pipeline.components.PipelineWarning#

Re-exported alias for lenskit.diagnostics.PipelineWarning.

class lenskit.pipeline.components.Lazy#

Re-exported alias for lenskit.lazy.Lazy.

exception lenskit.pipeline.components.TypecheckWarning#

Re-exported alias for lenskit.pipeline._types.TypecheckWarning.

lenskit.pipeline.components.is_compatible_data()#

Re-exported alias for lenskit.pipeline._types.is_compatible_data().