Skip to main content

The backbone for message-driven applications.

Project description

apos

The backbone for message-driven applications.

Summary

This Python library is designed to act as a software-level message broker, enabling a lightweight implementation of the publish-subscribe design pattern.

apos was born to accomplish two objectives:

  • Decouple the application layer from any interfaces
  • Develop reactive business functions

With apos, you can develop a message-driven application. This means that commands, events, and queries are sent to apos, which in return executes the functions that subscribe to these messages. This means that an adapter providing an external interface, may it be a web-API or a CLI, would not directly call application functions, but would rather send a message to apos, which will in return execute the business functions that subscribe to these messages. Equally, a business function would not call any other business function, but rather publishes an event, which other business functions can subscribe to and execute upon, controlled through apos.

Context

See the Medium article linked below to read about why this library was created and how it is intended to be used. https://mkossatz.medium.com/a-backbone-for-message-driven-applications-ffdcef67824c

Installation

The library can be found on PyPi: https://pypi.org/project/apos/

pip3 install apos

Getting Started

The code below is a very lightweight example of how you can use apos for commands, queries, and events.

from apos import apos


class RegisterUserCommand:
    pass


class UserRegisteredEvent:
    pass


class NewUserGreetedEvent:
    pass


class RetrieveUserQuery:
    pass


class RetrieveUserResponse:
    pass


def register_user(command: RegisterUserCommand) -> None:
    # Implementation of user registration
    apos.publish_event(
        UserRegisteredEvent())


def greet_new_user(event: UserRegisteredEvent) -> None:
    # Implementation of user greeting
    apos.publish_event(
        NewUserGreetedEvent())


def retrieve_user(query: RetrieveUserQuery) -> RetrieveUserResponse:
    # Implementation of user retrieval
    return RetrieveUserResponse()


# subscribing to messages (application configuration)
apos.subscribe_command(RegisterUserCommand, register_user)
apos.subscribe_event(UserRegisteredEvent, [greet_new_user])
apos.subscribe_query(RetrieveUserQuery, retrieve_user)

# some interface adapter
apos.publish_command(RegisterUserCommand())
events = apos.get_published_events()
print(events)
response: RetrieveUserResponse = apos.publish_query(RetrieveUserQuery())
print(response)

Complete Examples

You can find examples in the examples directory of the projects repository. https://github.com/mkossatz/apos/tree/main/examples

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

apos-0.2.1.2.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

apos-0.2.1.2-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file apos-0.2.1.2.tar.gz.

File metadata

  • Download URL: apos-0.2.1.2.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.6 Linux/5.13.13-200.fc34.x86_64

File hashes

Hashes for apos-0.2.1.2.tar.gz
Algorithm Hash digest
SHA256 78f7af43b0404779bb477d243d2b58fc206dcb321b413d471325c56f9497382f
MD5 7307807e34ae98704c4d4715ca33de05
BLAKE2b-256 632558782eff1b05d13b020482237ebb80de51b05ade0ddc542ba6d1ee4f86e3

See more details on using hashes here.

File details

Details for the file apos-0.2.1.2-py3-none-any.whl.

File metadata

  • Download URL: apos-0.2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.9.6 Linux/5.13.13-200.fc34.x86_64

File hashes

Hashes for apos-0.2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5f56654ebc079758027386afb59171813acc53a1c77dba2570e9582aa7425932
MD5 a162f55ffff1c68ab50995abb8163c4d
BLAKE2b-256 d4b38bbbaa127b28b28fa3dd14b0d819ad1cc828db5a8f633a1df5d4b717afb0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page