Skip to content

fastmessage_handler

fastmessage.fastmessage_handler

FastMessage

FastMessage(
    default_output_device=None,
    validation_error_handler=None,
)

Bases: PipelineHandlerBase

Parameters:

Name Type Description Default
default_output_device Optional[str]

an optional default output device to send callback results to, unless mapped otherwise

None
validation_error_handler Optional[Callable[[InputDevice, MessageBundle, ValidationError], Optional[Union[PipelineResult, Iterable[PipelineResult]]]]]

an optional handler that will be called on validation errors, in order to give the user a chance to handle them gracefully

None

event_loop property

event_loop

the event loop used for running async functions (lazy initialized)

input_devices property

input_devices

returns all the input device names that has callbacks

create_service

create_service(
    *,
    input_device_manager,
    input_device_names=None,
    output_device_manager=None,
    **kwargs
)

creates a PipelineService, with this FastMessage object as its handler

Parameters:

Name Type Description Default
input_device_manager InputDeviceManager

the input device manager to read items from

required
input_device_names Optional[Union[List[str], str]]

Optional. the list of input device names to read from (defaults to all the registered mappings)

None
output_device_manager Optional[OutputDeviceManager]

Optional. the output device manager to use

None
**kwargs

passed to PipelineService init as is

{}

Returns:

Type Description
PipelineService

the created PipelineService

map

map(input_device=_DEFAULT, output_device=_DEFAULT)

this is the decorator method

Parameters:

Name Type Description Default
input_device str

the input device to register the decorated method on

_DEFAULT
output_device Optional[str]

optional output device to route the return value of the callback to. if callback returns None, no routing will be made even if 'output_device' is not None None means no output routing

_DEFAULT

register_callback

register_callback(
    callback, input_device=_DEFAULT, output_device=_DEFAULT
)

registers a callback to a device

Parameters:

Name Type Description Default
callback _CALLABLE_TYPE

the callback to register

required
input_device str

the input device to register the callback to

_DEFAULT
output_device Optional[str]

optional output device to route the return value of the callback to. None means no output routing. if callback returns None, no routing will be made even if 'output_device' is not None

_DEFAULT

register_validation_error_handler

register_validation_error_handler(handler)

registers optional handler that will be called on validation errors, in order to give the user a chance to handle them gracefully

Parameters:

Name Type Description Default
handler Callable[[InputDevice, MessageBundle, ValidationError], Optional[PipelineResult]]

the handler to register

required