flow-med
A high-performance, type-safe Mediator pattern implementation for Python 3.13+, built on top of flow-res and injector.
Features
- Result-Driven Development: Built-in support for
flow-resResult types, making error handling explicit and type-safe. - Scoped Registration: Application-owned registries keep handler discovery explicit and isolated.
- Dependency Injection: Seamless integration with the
injectorlibrary for robust dependency management. - Native Async Support: Designed from the ground up for
asynciowithAwaitableResultsupport for elegant method chaining. - Strict Type Safety: Public type contracts are checked by
pyright/mypy, with result-type validation at handler registration.
Installation
pip install flow-med
Quick Start
1. Define Request and Result
from flow_res import Result
from flow_med import Request
class GetUserRequest(Request[Result[str, Exception]]):
def __init__(self, user_id: int):
self.user_id = user_id
2. Implement Handler
Register concrete handlers with an application-owned HandlerRegistry. Use
@override to ensure correct implementation.
from typing import override
from flow_res import Ok, Result
from flow_med import HandlerRegistry, RequestHandler
registry = HandlerRegistry()
@registry.handler
class GetUserHandler(RequestHandler[GetUserRequest, Result[str, Exception]]):
@override
async def handle(self, request: GetUserRequest) -> Result[str, Exception]:
# Logic to get user
return Ok(f"User {request.user_id}")
3. Create a Mediator and Send
import asyncio
from injector import Injector
from flow_med import Mediator
async def main():
# Each application owns its Registry, Mediator, and Injector.
mediator = Mediator(Injector(), registry)
# Send request and chain results using flow-res
result = await (
mediator.send_async(GetUserRequest(user_id=1))
.map(lambda name: f"Hello, {name}!")
.unwrap()
)
print(result) # Hello, User 1!
if __name__ == "__main__":
asyncio.run(main())
Registries are live references. Handlers added or explicitly replaced after a
Mediator is created are visible to that mediator. Configure registries during
application startup; concurrent registry mutation is not guaranteed to be
thread-safe. Separate registries are isolated, while sharing a registry
explicitly shares its handler mappings.
Migrating from v0.1
v0.2 replaces the process-wide class API with instance-owned mediators and scoped registries:
# v0.1
Mediator.initialize(Injector())
result = await Mediator.send_async(GetUserRequest(user_id=1)).unwrap()
# v0.2
registry = HandlerRegistry()
registry.handler(GetUserHandler)
mediator = Mediator(Injector(), registry)
result = await mediator.send_async(GetUserRequest(user_id=1)).unwrap()
For test-specific overrides, create a separate registry or call
mediator.register(...) and mediator.replace(...).
Requirements
License
MIT License
Metadata
Release files for flow-med 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flow_med-0.2.0.tar.gz | 30.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flow_med-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 36.5 kB
Release files / flow_med-0.2.0.tar.gz
| Download URL | flow_med-0.2.0.tar.gz |
|---|---|
| Size | 30.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f60dca51b519017e845942a9704effaaac7edca006e93686529492299fc4993
|
|
BLAKE2b-256 checksum How to use checksums |
1ce577a3b36dc3425005cc77f1dc209af92a5362618306f4fb7378c4319c0a6b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 28, 2026.
Transparency logRelease files / flow_med-0.2.0-py3-none-any.whl
| Download URL | flow_med-0.2.0-py3-none-any.whl |
|---|---|
| Size | 6.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6d4017133ebc059d3673b6214ab9a3ce5283f07d6f2535ef58571ecd0e20546b
|
|
BLAKE2b-256 checksum How to use checksums |
4a3eb850e1b9d75e050915955d75ff588245355e860245f089d32c383695ad03
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.14
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 28, 2026.
Transparency log