API reference
The public PyMediate types, grouped by dispatch and composition role.
This reference describes PyMediate's public classes, methods, type parameters, attributes, and exceptions. Start with the introduction or quick start if you want a guided request flow.
Requests
| API | Role |
|---|---|
Request[ResponseT] | Declares the response type returned for a request |
RequestHandler[RequestT] | Handles one request type |
Mediator.send() | Routes a request and returns its declared response type |
Streaming
| API | Role |
|---|---|
StreamRequest[ChunkT] | Declares the type of each streamed chunk |
StreamRequestHandler[StreamReqT] | Yields chunks for one stream-request type |
Mediator.stream() | Routes a stream request and returns an iterator |
Notifications
| API | Role |
|---|---|
Notification | Base class for a fact published without a response |
NotificationHandler[NotificationT] | Handles one notification type; several handlers may subscribe |
Mediator.publish() | Delivers a notification to its registered subscribers |
Request pipelines
| API | Role |
|---|---|
PipelineBehavior[RequestT] | Wraps send() for selected request types |
Next[ResponseT] | Calls the next behavior or request handler and returns ResponseT |
Pipeline behaviors do not wrap stream() or publish().
Service resolution
| API | Role |
|---|---|
Services | Registers service instances during setup |
ServiceProvider | Read-only protocol used by the mediator for resolution |
DependencyInjectorServiceProvider | Optional adapter for a Dependency Injector container |
Exceptions
The errors reference separates handler validation, dispatch, and service-resolution failures. Most PyMediate validation and dispatch exceptions inherit from PyMediateError; ServiceNotFoundError is separate, subclassing KeyError (a provider is a type-keyed mapping), and raised by service resolution.
Asynchronous and synchronous definitions
The top-level pymediate namespace contains asynchronous mediator, handler, behavior, and Next definitions. pymediate.sync contains their blocking counterparts. Message types, services, service-provider types, and exceptions are shared between the namespaces.