Skip to main content

slck-mediator — Python

Cross-language Mediator pattern framework for Python.
Send/stream/publish · 11-middleware pipeline · outbox · inbox · saga · integration event bus · full observability.

📖 Full Documentation

Installation

pip install slck-mediator

With optional extras:

pip install "slck-mediator[otel]"    # OpenTelemetry adapters
pip install "slck-mediator[sql]"     # SQLAlchemy adapters
pip install "slck-mediator[mongo]"   # Motor (MongoDB) adapters
pip install "slck-mediator[all]"     # Everything

Quick Start

from mediator import Mediator, Request, ConsoleLogger, InMemoryMetrics, InMemoryTracer

class GreetCommand(Request[str]):
    def __init__(self, name: str) -> None:
        self.name = name

async def greet_handler(ctx, cmd: GreetCommand) -> str:
    return f"Hello, {cmd.name}!"

async def main():
    logger  = ConsoleLogger()
    metrics = InMemoryMetrics()
    tracer  = InMemoryTracer("app", logger, metrics)
    m = Mediator(logger=logger, metrics=metrics, tracer=tracer)
    m.register_request_handler(GreetCommand, greet_handler)

    result = await m.send(GreetCommand("World"))
    print(result)  # Hello, World!

Code Generation

Generate a build-time direct-dispatch mediator from your feature handlers:

python tools/generate_mediator.py

Development

pip install -e ".[dev]"
pytest

Key modules:

  • tools/generate_mediator.py: build-time direct-dispatch generator for the example package with duplicate, missing-handler, polymorphic notification, generic-contract, and unsupported-constructor-or-factory diagnostics, and inherited-request-or-stream-contract diagnostics, and handler-or-message-discovery diagnostics
  • example/generated_mediator.py: generated direct-dispatch, polymorphic notification resolution, service registration, typed mediator facade, and dependency-wiring factory used by the example composition root
  • mediator/mediator.py: async runtime mediator with send, stream, and publish
  • mediator/registry.py: runtime request, stream, and notification registry
  • mediator/pipeline.py: middleware behaviors including rate limiting and bulkhead controls
  • mediator/eventbus.py: integration event transports, including concrete Kafka producer, NATS client, RabbitMQ client, and SQS client-backed adapters, plus versioned JSON envelope serializers
  • mediator/outbox.py: file-backed, in-memory, and adapter-backed outbox store, dead-letter store and replay manager, and worker
  • mediator/inbox.py: file-backed, in-memory, and adapter-backed idempotent consumer inbox support
  • mediator/saga.py: saga orchestration with durable file persistence and adapter-backed optimistic stores
  • mediator/lifecycle.py: hosted worker lifecycle, health/readiness, and graceful shutdown coordination
  • mediator/fastapi.py: FastAPI dependency helper
  • example/main.py: runnable CQRS, stream, outbox, inbox, and saga demo using the generated service collection/provider integration and typed mediator facade

Built-in notification publishers: ForeachAwaitPublisher, TaskWhenAllPublisher, plus compatibility aliases for SequentialNotificationPublisher and ParallelNotificationPublisher.

Versioned integration messages use a canonical JSON envelope with specVersion, version, schema, occurredAt, and idempotencyKey, and the example logs both the serialized envelope and round-trip deserialization.

Metadata

Release files for slck-mediator 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for slck-mediator 1.0.2
File Size Uploaded Provenance Actions
slck_mediator-1.0.2.tar.gz 34.2 kB Without provenance Details for slck_mediator-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for slck-mediator 1.0.2
File Interpreter ABI Platform Actions
slck_mediator-1.0.2-py3-none-any.whl Python 3 none any Details for slck_mediator-1.0.2-py3-none-any.whl

Total release size: 71.6 kB

Release files / slck_mediator-1.0.2.tar.gz

Download URL slck_mediator-1.0.2.tar.gz
Size 34.2 kB
Tags Source
SHA-256 checksum
How to use checksums
07bb1d7f0b800e9b1ff41cf4d614e32b4feb25385944d2d7cf23238253ec7245
BLAKE2b-256 checksum
How to use checksums
e126ba2d8d5982ade323fd14038aa8b9e10634ce9e67d133b6b7b86421f8f58e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.4

Release files / slck_mediator-1.0.2-py3-none-any.whl

Download URL slck_mediator-1.0.2-py3-none-any.whl
Size 37.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d6cc3db72ed9e2d639ed41a3b85b59c0f0eee81f159f64338a9c1631e1bc6c7e
BLAKE2b-256 checksum
How to use checksums
7fddfd5028c1dc7fd1b34a17c1a0527de6dc190c979141dc8c5fbb60346054de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.4

Security for slck-mediator 1.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page