Skip to main content

Cross-language Mediator pattern framework — send/stream/publish, 11-middleware pipeline, outbox, inbox, saga, and event bus

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slck_mediator-1.0.2.tar.gz (34.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slck_mediator-1.0.2-py3-none-any.whl (37.4 kB view details)

Uploaded Python 3

File details

Details for the file slck_mediator-1.0.2.tar.gz.

File metadata

  • Download URL: slck_mediator-1.0.2.tar.gz
  • Upload date:
  • Size: 34.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.4

File hashes

Hashes for slck_mediator-1.0.2.tar.gz
Algorithm Hash digest
SHA256 07bb1d7f0b800e9b1ff41cf4d614e32b4feb25385944d2d7cf23238253ec7245
MD5 d90131ac999d62c4da32524c3d263c83
BLAKE2b-256 e126ba2d8d5982ade323fd14038aa8b9e10634ce9e67d133b6b7b86421f8f58e

See more details on using hashes here.

File details

Details for the file slck_mediator-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: slck_mediator-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 37.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.4

File hashes

Hashes for slck_mediator-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d6cc3db72ed9e2d639ed41a3b85b59c0f0eee81f159f64338a9c1631e1bc6c7e
MD5 145c32c3d134b2f9e15b1e290a1e99d4
BLAKE2b-256 7fddfd5028c1dc7fd1b34a17c1a0527de6dc190c979141dc8c5fbb60346054de

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page