imbed.components.components_util#

Utils for components

Functions

add_default_key(d, default_key[, ...])

Add a 'default' key to a registry pointing to a specified component.

get_component_store(component)

Get the store for a specific component type

get_standard_components([refresh])

Get the standard components for the project.

Classes

ComponentRegistry(name, *[, factory])

A dict-based registry with decorator support for registration.

class imbed.components.components_util.ComponentRegistry(name, *, factory=None)[source]#

Bases: dict

A dict-based registry with decorator support for registration.

This registry provides:

  • Decorator-based registration with @registry.register()

  • Custom key support with @registry.register(‘custom_key’)

  • Direct registration via registry.register_item(key, item)

  • Optional factory functions to wrap registered items

  • Full dict compatibility for backward compatibility

Examples

>>> registry = ComponentRegistry('my_components')
>>> @registry.register()
... def my_function(x):
...     return x * 2
>>> registry['my_function'](5)
10
>>> @registry.register('custom_name')
... def another_function(x):
...     return x + 1
>>> registry['custom_name'](5)
6
register(key=None, **config)[source]#

Decorator to register a component.

Parameters:
  • key (str) – Registration key (defaults to function/class name)

  • **config – Additional configuration passed to factory if present

Return type:

Callable[[T], T]

Returns:

Decorator function that registers and returns the component

Examples

>>> registry = ComponentRegistry('test')
>>> @registry.register()
... def my_func():
...     return 42
>>> registry['my_func']()
42
>>> @registry.register('custom')
... def other_func():
...     return 99
>>> registry['custom']()
99
register_item(key, item, **config)[source]#

Register an item directly (non-decorator usage).

Parameters:
  • key (str) – Registration key

  • item (Any) – Item to register

  • **config – Additional configuration passed to factory if present

Examples

>>> registry = ComponentRegistry('test')
>>> def my_func():
...     return 42
>>> registry.register_item('my_key', my_func)
>>> registry['my_key']()
42
imbed.components.components_util.add_default_key(d, default_key, enviornment_var=None)[source]#

Add a ‘default’ key to a registry pointing to a specified component.

Parameters:
  • d (dict) – The registry dict to add default to

  • default_key – Either a string key or a callable (uses __name__ as key)

  • enviornment_var – Optional environment variable to override default_key

Returns:

The modified dict

Raises:

ValueError – If the default_key is not found in the registry

imbed.components.components_util.get_component_store(component)[source]#

Get the store for a specific component type

imbed.components.components_util.get_standard_components(refresh=False)[source]#

Get the standard components for the project.

Returns:

A dictionary of standard components, each containing registered processing functions