Skip to main content

Production-oriented RabbitMQ integration for Flask, built on Pika

Project description

Flask-RMQ

License: MIT Ruff PyPI PyPI pyversions PyPI status PyPI downloads PyPI types


RabbitMQ Support Flask Support


Documentation: https://flask-rmq.rdd-lab.com/

Source Code: https://github.com/RDDLab/Flask-RMQ


Flask-RMQ

Flask-RMQ provides typed RabbitMQ wrappers and tools for Flask applications using Pika.

It is not a task queue or a Celery replacement. It is a lightweight integration layer for services that need explicit message contracts, reliable publication, long-running consumers, topology management, and multiple independent RabbitMQ brokers.

Main features:

  • standard Flask extension and app-factory integration;
  • Click commands under the native flask rmq CLI group;
  • separate thread-local producer and consumer connections;
  • publisher confirms, persistent delivery, and mandatory=True routing;
  • bounded producer retry and consumer exponential backoff;
  • durable queues and dead-letter routing through QueueConfig;
  • per-alias topology and consumer registries;
  • optional Prometheus instrumentation;
  • Python typing with a py.typed marker.

Installation

Install Flask-RMQ with pip or your preferred Python package manager:

pip install Flask-RMQ

Prometheus support is optional:

pip install 'Flask-RMQ[metrics]'

Flask-RMQ supports Python 3.10–3.14 and Flask 3.0–3.1.

Minimal application

import json

from flask import Flask
from flask_rmq import (
    Consumer,
    FlaskRMQ,
    Producer,
    get_consumers_registry,
    get_setup_registry,
)

rmq = FlaskRMQ()
producer = Producer(queue='events')
consumer = Consumer(queue='events')


@consumer
def handle_event(channel, method, properties, body: bytes) -> None:
    print(json.loads(body))
    channel.basic_ack(delivery_tag=method.delivery_tag)


def setup_topology(channel) -> None:
    channel.queue_declare(queue='events', durable=True)


def create_app() -> Flask:
    app = Flask(__name__)
    app.config['RABBITMQ_CONNECTIONS'] = {
        'default': {'HOST': 'localhost'},
    }
    rmq.init_app(app)
    with app.app_context():
        get_setup_registry().register(setup_topology)
        get_consumers_registry().register(consumer)
    return app
flask --app your_app:create_app rmq check
flask --app your_app:create_app rmq setup
flask --app your_app:create_app rmq consume

Publish from a Flask route or service:

producer.publish(json.dumps({'event': 'created'}))

The complete runnable producer/consumer project is available in examples/basic_app.

Tests

python -m venv .venv
. .venv/bin/activate
pip install -e '.[dev,metrics]'
pytest
ruff check .
python -m build

The unit test suite does not require a live RabbitMQ broker. Use the example project for an end-to-end broker test.

Documentation portal

The VuePress portal contains complete English and Russian guides for configuration, producers, consumers, topology, CLI, reliability, metrics, the example project, and migration from Django-RMQ.

npm install
npm run docs:dev
npm run docs:build

MIT licensed.

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

flask_rmq-0.1.1.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

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

flask_rmq-0.1.1-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

Details for the file flask_rmq-0.1.1.tar.gz.

File metadata

  • Download URL: flask_rmq-0.1.1.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flask_rmq-0.1.1.tar.gz
Algorithm Hash digest
SHA256 ddc8422f907608c26a4c5f002e8926c704251411c567a869b559374b3742785b
MD5 fe4852ed659052d3fe60b2f6e2ec8dce
BLAKE2b-256 2226fdaf773956d71eb477dd860ce01b6ad21286d6207583f6c47c2d12162f0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_rmq-0.1.1.tar.gz:

Publisher: publish.yml on RDDLab/Flask-RMQ

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flask_rmq-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: flask_rmq-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 22.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flask_rmq-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 04bd2430aeba63ef5e1c3532bef67cdd5bf8fd67659d0a683a06ea318189a14d
MD5 60252d41c22447617b779d33f001791e
BLAKE2b-256 de7a5da50b57403ff8630994cf9fa4f4ad11eefc97bdf22fc5b8b527f6ac3b0d

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_rmq-0.1.1-py3-none-any.whl:

Publisher: publish.yml on RDDLab/Flask-RMQ

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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