Skip to main content

Aiorazemax

Build Status

✉️ Async communications using AWS SNS + SQS for Python services ✨

Documentation

In-Memory event manager

Show me the code

from aiorazemax.event_manager import EventManager


class NorthKoreaThreatCreatedEvent:
    def __init__(self, id, target):
        self.id = id
        self.target = target


async def trump_subscriber(event: NorthKoreaThreatCreatedEvent):
    print(f"North korea will attack us or {event.target}!")


EventManager.subscribe(trump_subscriber, NorthKoreaThreatCreatedEvent)
await EventManager.trigger(NorthKoreaThreatCreatedEvent(0, "Mexico"))

Result:

North korea will attack us or Mexico!

Trigger subscribers from SQS

Preconditions

SQS queue has to be subscribed to SNS topic before running the consumer

Code

import asyncio

from aiorazemax.consumers import MessageConsumer
from aiorazemax.drivers import SQSDriver
from aiorazemax.event_manager import EventManager
from aiorazemax.publisher import SNSMessagePublisher


aws_settings = {
    'region_name': "",
    'aws_access_key_id': "",
    'aws_secret_access_key': "",
    'endpoint_url': ""
}


class NorthKoreaThreatCreatedEvent:
    def __init__(self, id, target):
        self.id = id
        self.target = target


def kp_message_to_event(event_message):
    message = event_message.body
    # Highly recommended to use Marshmallow to validate
    return NorthKoreaThreatCreatedEvent(message['body']['id'], message['body']['target_name'])


mapper = {
    'KPThreatCreated': kp_message_to_event
}


async def trump_subscriber(event: NorthKoreaThreatCreatedEvent):
    print(f"North korea will attack us or {event.target}!")


async def main():
    EventManager.subscribe(trump_subscriber, NorthKoreaThreatCreatedEvent)

    queue_driver = await SQSDriver.build('korea-threats-queue', aws_settings)
    consumer = MessageConsumer(mapper, EventManager, queue_driver)

    publisher = await SNSMessagePublisher.build('korea-topic', aws_settings)
    await publisher.publish('KPThreatCreated', {'id': 21, 'target_name': 'Portugal'})

    await consumer.process_message()

    await queue_driver.close()
    await publisher.close()


if __name__ == '__main__':
    asyncio.run(main())

Result:

North korea will attack us or Portugal!

Installing

pip install aiorazemax

Running the tests

To run end to end tests do:

make unit-tests
make integration-tests

Authors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Metadata

Release files for aiorazemax 0.0.1

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

Source distribution (sdist)

Source distribution for aiorazemax 0.0.1
File Size Uploaded Provenance Actions
aiorazemax-0.0.1.tar.gz 4.8 kB Without provenance Details for aiorazemax-0.0.1.tar.gz

Release files / aiorazemax-0.0.1.tar.gz

Download URL aiorazemax-0.0.1.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
51ea96fb4fcfaa1d174f617184480e173ddbe3ae67a08aa38a0126b88e4a8880
BLAKE2b-256 checksum
How to use checksums
977392dc8726cf2ef95307a1dff73647fd0cb7b2f387aace19ae5b43650a102c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.7.1

Security for aiorazemax 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

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