API Documentation

Event Processor

class src.event_processor.event_processor.EventProcessor
add_subprocessor(subprocessor: src.event_processor.event_processor.EventProcessor)

Add a subprocessor for events.

This will update the current event processor with all the processors of the subprocesor, which means that invoking the main processor with an event will have the same effect as invoking the correct subprocessor.

Note that filters defined in subprocessors must not already exist in the main processor, otherwise an error will be raised.

Parameters

subprocessor – The subprocessor to add to the current processor.

Raises

EventProcessorSubprocessorException – When there is an overlap in filter expressions between the processor and subprocessor.

dependency_factory(fn: Callable)

Register a dependency factory.

The name of the function will be the name of the factory, so this is what must be used in processor decorators. Also, the function must take a single string parameter and return a dependency based on that.

Parameters

fn – The function that will act as a factory.

Raises
invoke(event: Dict)Any

Invoke an event processor for the given event.

The correct processor will automatically be selected based on the event, and its dependencies will be automatically created and injected.

Parameters

event – The raw event.

Returns

The value returned by the processor.

Raises
processor(filter_expr: Dict[str, Any], pre_processor: Callable[[Dict], Any] = <function passthrough>, **kwargs)

Decorate event processors.

Important Considerations

  • The keyword arg in the decorator must match the dependency factory function’s name.

  • The arguments are passed in the following order : event, dependencies.

  • All dependencies for a factory are passed before moving onto the next factory.

  • The argument names are not important, but the order must be followed.

Parameters
  • filter_expr – A dict containing path-value pairs to call the right event processor.

  • pre_processor – A pre-processor function to transform the event into another type.

  • kwargs – A mapping of dependency-factory to tuple of dependencies for that factory.

Raises

EventProcessorDecorationException – When the filter expression is already associated to a handler.

Exceptions

Exceptions for event processor.

exception EventProcessorDecorationException(msg: str, wrapped_fn: Callable)

Exception for failures while wrapping processors.

exception EventProcessorDependencyException(msg: str, wrapped_fn: Callable, dependencies: Dict[str, Tuple[str, ]])

Exception for failures in dependencies.

exception EventProcessorException(msg: str)

General exception for the event-processor library.

exception EventProcessorInvocationException(msg: str, event: Dict)

Exception for failures in invocation.

exception EventProcessorSubprocessorException(msg: str, overlap: Set)

Exception for failures in subprocessor management.

Processor

Contains a class which represents an event processor.

class processor.Processor(fn: Callable, pre_processor: Callable, dependencies: Dict[str, Tuple[str, ]])

Represent a registered processor.

Pre-Processors

Built-in event preprocessors.

pre_processors.passthrough(event)

Passthrough the event without touching it.

Parameters

event – The input event.

Returns

The input event.