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.0.tar.gz (15.8 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.0-py3-none-any.whl (22.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: flask_rmq-0.1.0.tar.gz
  • Upload date:
  • Size: 15.8 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.0.tar.gz
Algorithm Hash digest
SHA256 8fd22d614e8cc26ae26feec6e711e2e3a18cf44fa95c7aac48caddc0ab5d28db
MD5 a9778ad43c39c1ab62688f7e91daba10
BLAKE2b-256 70d9ecc29fc0c04433051456af0865d5ffb084aa70cabeaa8206c1a9722627fe

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_rmq-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: flask_rmq-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ffe6093c8b9a768273b0dde7154412859ed1a3a1a82f383e7a7a5f017aa3bede
MD5 d9f50daefef467e8d87eec085b5d0703
BLAKE2b-256 16f0528a8f26af663aa0a6089ce540a7cd81fae2e62c152a13dbaa19678d87ee

See more details on using hashes here.

Provenance

The following attestation bundles were made for flask_rmq-0.1.0-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