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.1.tar.gz (25.3 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.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flow_med-0.1.1.tar.gz
  • Upload date:
  • Size: 25.3 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.1.tar.gz
Algorithm Hash digest
SHA256 1cf2c5612c2beccedfc8b53123d68ae0de228c094ea1b27f93bdf21789d16883
MD5 4b0e6d33c80c18a7ba4219dc4198e4b2
BLAKE2b-256 19994f05935873294d1ee0ecbfe036ce061b01e0a033b22336688e8f3fa1ff1d

See more details on using hashes here.

Provenance

The following attestation bundles were made for flow_med-0.1.1.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.1-py3-none-any.whl.

File metadata

  • Download URL: flow_med-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 33220b2b16a07eebded9e8531c78cd88ae39d99d5323a6e54095797d4122f1a0
MD5 ed13370aab0e3c90ac3baa226725c91d
BLAKE2b-256 06d284236fee8a7a69272f7ce4594fb24afa373d8bc4208e8960549ac18e5b5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for flow_med-0.1.1-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