lenskit.pipeline.Component#

class lenskit.pipeline.Component(*args, **kwargs)#

Bases: Configurable, Generic[COut]

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

Components are Configurable. The base class provides default implementations of get_config() and from_config() that inspect the constructor arguments and instance variables to automatically provide configuration support. By default, all constructor parameters will be considered configuration parameters, and their values will be read from instance variables of the same name. Components can also define EXTRA_CONFIG_FIELDS and IGNORED_CONFIG_FIELDS class variables to modify this behavior. Missing attributes are silently ignored.

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

__init__(*args, **kwargs)#

Methods

__init__(*args, **kwargs)

from_config(cfg)

Create a class from the specified construction.

get_config()

Get the configuration by inspecting the constructor and instance variables.

Attributes

EXTRA_CONFIG_FIELDS

Names of instance variables that should be included in the configuration dictionary even though they do not correspond to named constructor arguments.

IGNORED_CONFIG_FIELDS

Names of constructor parameters that should be excluded from the configuration dictionary.

EXTRA_CONFIG_FIELDS: ClassVar[list[str]] = []#

Names of instance variables that should be included in the configuration dictionary even though they do not correspond to named constructor arguments.

Note

This is rarely needed, and usually needs to be coupled with **kwargs in the constructor to make the resulting objects constructible.

IGNORED_CONFIG_FIELDS: ClassVar[list[str]] = []#

Names of constructor parameters that should be excluded from the configuration dictionary.

get_config()#

Get the configuration by inspecting the constructor and instance variables.

Return type:

dict[str, object]

classmethod from_config(cfg)#

Create a class from the specified construction. Configuration elements are passed to the constructor as keywrod arguments.

Parameters:

cfg (dict[str, Any])

Return type:

Self