Skip to main content

AMQP support for Sanic framework

Project description

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:

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

sanic-amqp-xtension-0.1.3.tar.gz (3.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sanic_amqp_xtension-0.1.3-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file sanic-amqp-xtension-0.1.3.tar.gz.

File metadata

  • Download URL: sanic-amqp-xtension-0.1.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for sanic-amqp-xtension-0.1.3.tar.gz
Algorithm Hash digest
SHA256 193dfecc4611454112402e69709e4daffde1249c5133cb7dfb3e0739180d80ad
MD5 f5162497b1c2e3f7c5cf6cd3844d730e
BLAKE2b-256 73bb029f639e4f2a6012715935c7d4b14022d925aa2e3469790e2d1566c12a59

See more details on using hashes here.

File details

Details for the file sanic_amqp_xtension-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: sanic_amqp_xtension-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 4.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.5

File hashes

Hashes for sanic_amqp_xtension-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e348afabb10ceeb4cadb5c671cb3d2398dafd11da5871ecdd9f2d2247b433011
MD5 b2cd56e60a63589581202265c5308026
BLAKE2b-256 64f29666de70c8259ad2fde5e0003ecb0a148e989b3f67b977d1bb22eab9d966

See more details on using hashes here.

Supported by

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