events#

class litestar.events.EventListener#

Bases: object

Decorator for event listeners

__init__(*event_ids: str) None#

Create a decorator for event handlers.

Parameters:

*event_ids – The id of the event to listen to or a list of event ids to listen to.

__call__(fn: AnyCallable) EventListener#

Decorate a callable by wrapping it inside an instance of EventListener.

Parameters:

fn – Callable to decorate.

Returns:

An instance of EventListener

static wrap_in_error_handler(fn: AsyncAnyCallable) AsyncAnyCallable#

Wrap a listener function to handle errors.

Listeners are executed concurrently in a TaskGroup, so we need to ensure that exceptions do not propagate to the task group which results in any other unfinished listeners to be cancelled, and the receive stream to be closed.

See litestar-org/litestar#2809

Parameters:

fn – The listener function to wrap.

class litestar.events.SimpleEventEmitter#

Bases: BaseEventEmitterBackend

Event emitter the works only in the current process

__init__(listeners: Sequence[EventListener]) None#

Create an event emitter instance.

Parameters:

listeners – A list of listeners.

emit(event_id: str, *args: Any, **kwargs: Any) None#

Emit an event to all attached listeners.

Parameters:
  • event_id – The ID of the event to emit, e.g ‘my_event’.

  • *args – args to pass to the listener(s).

  • **kwargs – kwargs to pass to the listener(s)

Returns:

None

class litestar.events.BaseEventEmitterBackend#

Bases: AbstractAsyncContextManager[BaseEventEmitterBackend], ABC

Abstract class used to define event emitter backends.

__init__(listeners: Sequence[EventListener]) None#

Create an event emitter instance.

Parameters:

listeners – A list of listeners.

abstract emit(event_id: str, *args: Any, **kwargs: Any) None#

Emit an event to all attached listeners.

Parameters:
  • event_id – The ID of the event to emit, e.g ‘my_event’.

  • *args – args to pass to the listener(s).

  • **kwargs – kwargs to pass to the listener(s)

Returns:

None

litestar.events.listener#

alias of EventListener