edri.api package¶
Subpackages¶
- edri.api.dataclass package
- edri.api.extensions package
- edri.api.grpc package
- edri.api.handlers package
- edri.api.headerkit package
- Submodules
- edri.api.headerkit.core module
HeadersHeaders.acceptHeaders.accept_encodingHeaders.accept_languageHeaders.all()Headers.authorizationHeaders.cache_controlHeaders.combined()Headers.content_lengthHeaders.content_typeHeaders.cookiesHeaders.dateHeaders.decode_value()Headers.etagHeaders.first()Headers.from_scope()Headers.hostHeaders.if_none_matchHeaders.list_members()Headers.names()Headers.normalize_name()Headers.parse()Headers.rangeHeaders.rawHeaders.raw_all()Headers.singleton()Headers.singleton_raw()
- edri.api.headerkit.defaults module
- edri.api.headerkit.errors module
- edri.api.headerkit.grammar module
- edri.api.headerkit.parsers module
- edri.api.headerkit.policy module
- edri.api.headerkit.registry module
- edri.api.headerkit.response module
- edri.api.headerkit.types module
- Module contents
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:
ABCAbstract 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:
objectEncapsulates the outcome of middleware processing with details on the action type, optional data, errors, and an optional replacement event.
- class ActionType(*values)[source]¶
Bases:
EnumEnum 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.
- 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:
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.