Skip to main content

Loudhailer

pyversions PyPi Status Test Loudhailer Quality Gate Status Coverage Maintainability Rating

Introduction

Loudhailer is a python library that allows to send broadcast messages to groups of consumers. It has been designed for being used in asynchronous applications.

This initial release natively supports RabbitMQ and Redis backends and can be easily extended to support more backends.

Loudhailer includes an extension that allows you to use in django-channels based projects.

Please note that the current version of Loudhailer have to be considered a beta release since it is still under heavy development.

Install

Loudhailer requires python 3.8 or later.

Loudhailer can be installed from pypi.org using pip:

$ pip install loudhailer

If you plan to use it with django-channels you must install the optional channels dependency:

$ pip install loudhailer[channels]

Basic usage

Publishing messages

from loudhailer import Loudhailer


async with Loudhailer('amqp://localhost') as loudhailer:
    await loudhailer.publish('my_group', {'message': 'data'})

Subscribe to group and receive messages

from loudhailer import Loudhailer


with Loudhailer('amqp://localhost') as loudhailer:
    with loudhailer.subscribe('my_group') as messages:
        message = await messages.get()
        print(f'received message: {message}')

Django channels extension

The django-channels extension is an implementation of the Channel Layers specifications.

In order to properly works it need to add a ASGI lifespan handler to your channels application.

Please note that Channel Layers specification are not yet fully implemented, only group messaging is supported in this initial release.

Django settings

Add the following Channel Layers configuration to your Django settings module:

CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'loudhailer.ext.channels.LoudhailerChannelLayer',
        'CONFIG': {
            'url': 'amqp://localhost',
        },
    },
}

Configure the ASGI lifespan handler

Add the following configuration to your root channels routing module:

from channels.routing import ProtocolTypeRouter, URLRouter
from loudhailer.ext.channels import LoudhailerChannelLifespan

application = ProtocolTypeRouter(
    {
        'lifespan': LoudhailerChannelLifespan.as_asgi(),
        'websocket': URLRouter(...),
    },
)

In case you already have an handler to process lifespan startup and shutdown events you can be notified of such event by the LoudhailerChannelLifespan handler in two ways:

Using django signals

You can register your signal handler for startup and shutdown events in the following way:

from django.dispatch import receiver
from loudhailer.ext.channels import asgi_application_shutdown, asgi_application_startup


@receiver(asgi_application_startup)
def handle_startup(sender, **kwargs):
    pass

@receiver(asgi_application_shutdown)
def handle_shutdown(sender, **kwargs):
    pass

Using on_startup and on_shutdown hooks

from channels.routing import ProtocolTypeRouter, URLRouter
from loudhailer.ext.channels import LoudhailerChannelLifespan

async def on_startup():
    pass


async def on_shutdown():
    pass


application = ProtocolTypeRouter(
    {
        'lifespan': LoudhailerChannelLifespan.as_asgi(
            on_startup=on_startup, on_shutdown=on_shutdown,
        ),
        'websocket': URLRouter(...),
    },
)

Please note that the on_startup and on_shutdown hooks can be implemented both as synchronous or asynchronous functions.

License

Loudhailer is released under the Apache License Version 2.0.

Metadata

Release files for loudhailer 0.3.4

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

Source distribution (sdist)

Source distribution for loudhailer 0.3.4
File Size Uploaded
loudhailer-0.3.4.tar.gz 13.3 kB Details

Built distribution (wheel)

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

Total release size: 28.3 kB

Release files / loudhailer-0.3.4.tar.gz

Download URL loudhailer-0.3.4.tar.gz
Size 13.3 kB
Tags Source
SHA-256 checksum
How to use checksums
15cd2f8e3693c4a0cfc5c2f3a0844d0dc8eac895bd0c7140206aa7f0ea995b95
BLAKE2b-256 checksum
How to use checksums
22b67d0d5d7a9b11cbe3f3324c9b8e857e1ac06036645dc7333073434a17d260
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.10.21 Linux/6.17.0-1022-azure

Release files / loudhailer-0.3.4-py3-none-any.whl

Download URL loudhailer-0.3.4-py3-none-any.whl
Size 15.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
120d0a0d8c80df6f5b6e83e6ad71102324f1705ce653839033f3617c90915d9c
BLAKE2b-256 checksum
How to use checksums
f616dcd6799c2cc1dcb7014eb181935442c4ac799a104aa233ce11034b373d7b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.5 CPython/3.10.21 Linux/6.17.0-1022-azure

Release history Release notifications | RSS feed

This release

0.3.4 This release

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.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