Skip to main content

RmediatoR

Introduction

RmediatoR is a Python package inspired by the MediatR library available on NuGet. It allows developers to implement the mediator design pattern in their applications, promoting a clean separation of concerns by centralizing request/response logic and eliminating direct dependencies between components. This package simplifies the communication between different parts of your application, making your code more maintainable and scalable.

Demonstration

Here's a quick example to demonstrate how RmediatoR works:

  1. Define a Request and Handler: Create a request class and a handler class that processes the request.
from rmediator.decorators import request, request_handler

# Define a response
class SomeResponse:
    def __init__(self, message):
        self.message = message

# Define a request
@request(SomeResponse)
class SomeRequest:
    ...

# Define a handler for the request
@request_handler(SomeRequest, SomeResponse)
class SomeRequestHandler:
    def handle(self, request: SomeRequest) -> SomeResponse:
        return SomeResponse("Handled!")
  1. Initialize the mediator and register the handlers
from rmediator import Mediator

mediator = Mediator()

mediator.register_handler(SomeRequest, SomeRequestHandler())
  1. Send a Request: Use the mediator to send a request and get a response.
# Create a request instance
request = SomeRequest()

# Send the request through the mediator
response = mediator.send(request)

# Output the response
print(response.message)  # Output: Handled!

How to Use

To start using RmediatoR, follow these steps:

  1. Installation: First, install the package using pip (or use other options like poetry).
pip install rmediator
  1. Creating Requests and Handlers: Define your request and handler classes as shown in the demonstration above. Each request should inherit from the Request class, and each handler should inherit from the Handler class.

  2. Registering Handlers: Register your handlers with the mediator. This tells the mediator which handler to use for each request type.

mediator.register_handler(YourRequestClass, YourHandlerClass)
  1. Sending Requests: Use the mediator to send requests. The mediator will find the appropriate handler and return the response.
response = mediator.send(your_request_instance)

License

RmediatoR is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome! Please read the CONTRIBUTING guidelines for more information on how to get started.

Contact

For questions or issues, please open an issue on GitHub or contact me on my channels.

Release files for rmediator 0.2.7

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

Built distribution (wheel)

Table of built distributions (wheels) for rmediator 0.2.7
File Interpreter ABI Platform
rmediator-0.2.7-py3-none-any.whl Python 3 none any Details

Release files / rmediator-0.2.7-py3-none-any.whl

Download URL rmediator-0.2.7-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
82bee056bd6f481a9923323b71a0327a8cd36f78d7deb6bc43be297115db56b4
BLAKE2b-256 checksum
How to use checksums
cd8f85e2f4fefaacb0b02fefbf688e54895517d391d26c9c7fe7716a0c02b90d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.13.2

Release history Release notifications | RSS feed

This release

0.2.7 This release

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

2 release files

0.2.0

2 release files

0.1.0

2 release files

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