Skip to main content

No project description provided

Project description

flow-med

PyPI version License: MIT Python 3.13+

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-res Result types, making error handling explicit and type-safe.
  • Auto-Registration: Handlers are automatically registered using Python 3.13's __init_subclass__ and generic introspection.
  • Dependency Injection: Seamless integration with the injector library for robust dependency management.
  • Native Async Support: Designed from the ground up for asyncio with AwaitableResult support for elegant method chaining.
  • Strict Type Safety: Fully compatible with pyright and mypy using modern Python 3.13 type parameters.

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

Handlers are automatically registered when defined. Use @override to ensure correct implementation.

from typing import override
from flow_res import Ok, Result
from flow_med import RequestHandler

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. Initialize and Send

import asyncio
from injector import Injector
from flow_med import Mediator

async def main():
    # Initialize with an Injector
    Mediator.initialize(Injector())

    # 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())

Requirements

License

MIT License

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

flow_med-0.1.0.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

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

flow_med-0.1.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file flow_med-0.1.0.tar.gz.

File metadata

  • Download URL: flow_med-0.1.0.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flow_med-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6f747b4e1c4adb4595988fbe78bacf125a15f197eff2f823c82bb2ae2baa57ac
MD5 d072050e9162c2c8d81636060840ea95
BLAKE2b-256 a1a5ae0223a8c6259baa582a08b9fdd4b1aff67755ccc570ece2906b3e987440

See more details on using hashes here.

Provenance

The following attestation bundles were made for flow_med-0.1.0.tar.gz:

Publisher: publish-prod.yml on aiagate/flow-med

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flow_med-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flow_med-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flow_med-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 339cc829c94de0d05c41061cea114b98318a165e38f85bac027998fbd7fb1398
MD5 9183f26efbf54b193d74d68dd7f94728
BLAKE2b-256 610d83171fc8a4abda1fd497d0a8e4974da846c82998e343e8ddf19788fb2b34

See more details on using hashes here.

Provenance

The following attestation bundles were made for flow_med-0.1.0-py3-none-any.whl:

Publisher: publish-prod.yml on aiagate/flow-med

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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