Skip to main content

AMQP support for Sanic framework

Features

  • Based on the aioamqp library

  • Provides an opportunity to implement workers that works in background

Installation

This package should be installed using pip:

pip install sanic-amqp-extension

Example

from sanic import Sanic, response
from sanic_amqp_ext import AmqpExtension, AmqpWorker


app = Sanic(__name__)
# Configuration for RabbitMQ
app.config.update({
    "AMQP_USERNAME": "guest",
    "AMQP_PASSWORD": "guest",
    "AMQP_HOST": "localhost",
    "AMQP_PORT": 5672,
    "AMQP_VIRTUAL_HOST": "vhost",
    "AMQP_USING_SSL": False,
})
AmqpExtension(app) # AMQP is available as `app.amqp` or `app.extensions['amqp']`


class CustomWorker(AmqpWorker):

    async def run(self, *args, **kwargs):
        transport, protocol = await self.connect()  # create a new connection
        # and do some stuff here ...

# Register workers after initializing the extension
app.amqp.register_worker(CustomWorker(app))


@app.route("/")
async def handle(request):
    transport, protocol = await request.app.amqp.connect()  # create a new connection
    # do some stuff here ...
    # P.S. but don't forget to close the connection after using
    return response.text("It's works!")

License

The sanic-amqp-extension is published under BSD license. For more details read LICENSE file.

Real project examples

Open Matchmaking project:

Metadata

Release files for sanic-amqp-extension 0.2.0

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

Source distribution (sdist)

Source distribution for sanic-amqp-extension 0.2.0
File Size Uploaded
sanic-amqp-extension-0.2.0.tar.gz 4.3 kB Details

Release files / sanic-amqp-extension-0.2.0.tar.gz

Download URL sanic-amqp-extension-0.2.0.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
59d308de7f6412f231bbb577fea654375b2665c946146b54892cc2114e027133
BLAKE2b-256 checksum
How to use checksums
71d0b4d8d83d66e7803b498e236c1e36f65385514ff450b86a581534620087db
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.5

Release history Release notifications | RSS feed

This release

0.2.0 This release

1 release file

0.1.2

2 release files

0.1.1

1 release file

0.1.0

1 release file

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