edri.api package

Subpackages

Submodules

edri.api.broker module

class edri.api.broker.EventInfo(resource: str | None, handling_type: edri.dataclass.event.EventHandlingType)[source]

Bases: object

edri.api.event_builder module

Transport-agnostic Event construction from raw parameters.

Extracted from BaseHandler (edri/api/handlers/base_handler.py) so a non-ASGI caller — a future gRPC listener, in particular — can build an Event from a plain dict[str, Any] without going through the ASGI handler hierarchy. BaseHandler keeps its existing method names as thin delegates to these functions, so current behavior (including subclass overrides layered on top, e.g. HTTPHandler injecting headers/cookies before calling into this) is unchanged.

edri.api.event_registry module

Runtime registry that maps event types to their API extensions (URL, method, cookies, headers, scope, template).

Populated at startup by edri.api.dataclass.api_event.api(). Read at request time by handlers to resolve incoming requests to the correct event type.

edri.api.listener module

edri.api.middleware module

class edri.api.middleware.Middleware[source]

Bases: ABC

Abstract base class for middleware components. Middleware classes derived from this must implement at least one of 'process_request' and 'process_response'.

process_request(event: Event, info: EventInfo | None) → MiddlewareControl[source]

Method to process the request before it reaches the main application logic. This method should be implemented in a subclass to perform any necessary preprocessing or validation on the request.

Parameters:
  • event -- The request event to be processed.

  • info -- Information about the event.

Returns:

A MiddlewareControl object indicating whether to continue processing, skip further middleware, or terminate the request/response cycle.

process_response(event: Event, info: EventInfo | None) → MiddlewareControl[source]

Method to process the response before it is sent to the client. This method should be implemented in a subclass to perform any necessary postprocessing or formatting on the response.

Parameters:
  • event -- The response event to be processed.

  • info -- Information about the event.

Returns:

A MiddlewareControl object indicating whether to continue processing, skip further middleware, or terminate the request/response cycle.

static register_events() → tuple[list[Type[Event]], list[Type[Event]]][source]

Registers events which suppose to be delivered to broker which are before processing handled by middlewares. It supposes to allow user to use custom Events to, for example, authenticate WebSocket connections. In combination with MiddlewareControl.REDIRECT and MiddlewareControl.REPLACE_EVENT is a powerful tool to handle specific situations.

Args:

Returns:

  • A tuple of two lists, where each list contains event objects first for request and second for response.

class edri.api.middleware.MiddlewareControl(action: ActionType, event: Event | None = None)[source]

Bases: object

Encapsulates the outcome of middleware processing with details on the action type, optional data, errors, and an optional replacement event.

class ActionType(*values)[source]

Bases: Enum

Enum to define middleware processing actions.

CONTINUE = 1
REDIRECT = 4
REPLACE_EVENT = 3
STOP = 2
classmethod continue_processing() → Self[source]

Creates a MiddlewareControl instance indicating processing should continue.

event: Event | None = None
classmethod redirect_event(event: Event) → Self[source]

Creates a MiddlewareControl instance that redirects the event (changes request to response or vice versa).

Parameters:

event (Event) -- The event to redirect.

Returns:

An instance with action set to REDIRECT.

Return type:

MiddlewareControl

classmethod replace_event(event: Event) → Self[source]

Creates a MiddlewareControl instance that replaces the current event with a new one.

Parameters:

event (Event) -- The event that should replace the current event in processing.

Returns:

An instance with action set to REPLACE_EVENT.

Return type:

MiddlewareControl

classmethod stop_processing() → Self[source]

Creates a MiddlewareControl instance indicating processing should stop.

edri.api.pipes module

Transport-agnostic client<->Broker pipe plumbing.

Extracted from Listener.App (edri/api/listener.py) so a non-ASGI listener — a future gRPC front end, in particular — can register a client with Broker and exchange Events over a pipe without going through the ASGI Listener class. Behavior matches the original 1:1; Listener.App keeps its existing method names as thin delegates to ClientRegistry so its own calling code (http()/websocket()) is unchanged.

Module contents