Skip to main content

Asynchronous Communication Framework

Project description

Message Flow

CI Coverage
pypi downloads
license

Message Flow is a first Web framework for building event-driven applications with Python 3.10+.

Asynchronous APIs, which allow servers to push notifications and data directly to the client as soon as available, are becoming increasingly important in modern applications that offer instant feedback and streaming data. Message Flow gives you all the tools needed to implement asynchronous APIs.

Why use Message Flow

  • Fully-featured: Supports pub-sub and request-async response communication patterns.
  • Easy: Designed to be easy to use and learn. Less time reading docs.
  • Reliable: Production-ready framework, equipped with automated, interactive documentation.
  • Standards-based: Based on (and fully compatible with) the open standard AsyncAPI and JSON Schema.

Installation

Installing Message Flow is as simple as:

pip install message-flow

Requirements

Python 3.10+

  • Pydantic for the messages serialization and deserialization.

Message Flow Examples

To see Message Flow at work, let's start with a simple example, creating a consumer and publisher of OrderCreated event:

  • Create a file publisher.py with:
from message_flow import MessageFlow, Message, Payload, Header


class OrderCreated(Message):
    order_id: str = Payload()
    tenant_id: str = Header()


if __name__ == "__main__":
    app = MessageFlow()

    app.publish(OrderCreated(order_id="order_id", tenant_id="tenant_id"), channel_address="orders")
    
  • Create a file dispatcher.py with:
from message_flow import MessageFlow, Message, Payload, Header


class OrderCreated(Message):
    order_id: str = Payload()
    tenant_id: str = Header()


if __name__ == "__main__":
    app = MessageFlow()

    @app.subscribe(address="orders", message=OrderCreated)
    def order_created_handler(order_created: OrderCreated) -> None:
        print("Event received", order_created.order_id, order_created.tenant_id)

    app.dispatch()
  • Run the dispatcher with:
$ python dispatcher.py
  • Open another terminal and publish message with:
$ python publisher.py
  • In terminal with running dispatcher you should see the following message:
Event received order_id tenant_id

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

message_flow-0.3.7.tar.gz (36.5 kB view details)

Uploaded Source

Built Distribution

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

message_flow-0.3.7-py3-none-any.whl (50.5 kB view details)

Uploaded Python 3

File details

Details for the file message_flow-0.3.7.tar.gz.

File metadata

  • Download URL: message_flow-0.3.7.tar.gz
  • Upload date:
  • Size: 36.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for message_flow-0.3.7.tar.gz
Algorithm Hash digest
SHA256 c2015e7f75ed29f91da8a29feea1fd1d77f66ef657055ec7988131983532edf2
MD5 a78e96c2474f91da7961136d8d30c423
BLAKE2b-256 1ab831534fef44d6e9b25f51283ffca724691c3608de0cb80716c3bb5880f526

See more details on using hashes here.

File details

Details for the file message_flow-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: message_flow-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 50.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for message_flow-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 954c77cf782bc1f266e6b62c80d485f21964aa32db40eb6dac3ab271d05c186b
MD5 a4c9b04cbaa47bb2abce19aa88fbc24e
BLAKE2b-256 dda3fcfbb259570ed6ff9ac98e3f8fbaee273f227c117e2be36ae5ea3ed86946

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