Skip to main content

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

Release files for apos 0.2.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apos 0.2.1.2
File Size Uploaded
apos-0.2.1.2.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for apos 0.2.1.2
File Interpreter ABI Platform
apos-0.2.1.2-py3-none-any.whl Python 3 none any Details

Total release size:10.2 kB

Release files / apos-0.2.1.2.tar.gz

Download URL apos-0.2.1.2.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
78f7af43b0404779bb477d243d2b58fc206dcb321b413d471325c56f9497382f
BLAKE2b-256 checksum
How to use checksums
632558782eff1b05d13b020482237ebb80de51b05ade0ddc542ba6d1ee4f86e3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.6 Linux/5.13.13-200.fc34.x86_64

Release files / apos-0.2.1.2-py3-none-any.whl

Download URL apos-0.2.1.2-py3-none-any.whl
Size 5.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f56654ebc079758027386afb59171813acc53a1c77dba2570e9582aa7425932
BLAKE2b-256 checksum
How to use checksums
d4b38bbbaa127b28b28fa3dd14b0d819ad1cc828db5a8f633a1df5d4b717afb0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.6 CPython/3.9.6 Linux/5.13.13-200.fc34.x86_64

Release history Release notifications | RSS feed

This release

0.2.1.2 This release

2 release files

0.2.1

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page