Metadata-Version: 2.4
Name: Flask-RMQ
Version: 0.1.1
Summary: Production-oriented RabbitMQ integration for Flask, built on Pika
Author: RDD Lab
License: MIT
Project-URL: Documentation, https://flask-rmq.rdd-lab.com/
Project-URL: Issues, https://github.com/RDDLab/Flask-RMQ/issues
Project-URL: Repository, https://github.com/RDDLab/Flask-RMQ
Keywords: flask,rabbitmq,amqp,pika,messaging
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Framework :: Flask
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: System :: Networking
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: Flask<4.0,>=3.0
Requires-Dist: click>=8.1
Requires-Dist: pika<2.0,>=1.3.2
Provides-Extra: metrics
Requires-Dist: prometheus-client<1.0,>=0.20; extra == "metrics"
Provides-Extra: dev
Requires-Dist: build>=1.2; extra == "dev"
Requires-Dist: mypy>=1.10; extra == "dev"
Requires-Dist: pytest>=8.0; extra == "dev"
Requires-Dist: pytest-cov>=5.0; extra == "dev"
Requires-Dist: ruff>=0.9; extra == "dev"
Dynamic: license-file

![Flask-RMQ](docs/.vuepress/public/logo-horizontal.svg)

[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json&style=for-the-badge)](https://docs.astral.sh/ruff)
[![PyPI](https://img.shields.io/pypi/v/Flask-RMQ?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
[![PyPI pyversions](https://img.shields.io/pypi/pyversions/Flask-RMQ.svg?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
[![PyPI status](https://img.shields.io/pypi/status/Flask-RMQ.svg?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
[![PyPI downloads](https://img.shields.io/pypi/dm/Flask-RMQ?style=for-the-badge)](https://pypistats.org/packages/flask-rmq)
[![PyPI types](https://img.shields.io/pypi/types/Flask-RMQ.svg?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)

---

[![RabbitMQ Support](https://img.shields.io/static/v1?label=RabbitMQ%20Support&message=v3.13%20%7C%20v4.0%20%7C%20v4.1%20%7C%20v4.2%20%7C%20v4.3&color=ff6600&labelColor=555&style=for-the-badge)](https://www.rabbitmq.com/)
[![Flask Support](https://img.shields.io/static/v1?label=Flask%20Support&message=v3.0%20%7C%20v3.1&color=00a878&labelColor=555&style=for-the-badge)](https://flask.palletsprojects.com/)

---

**Documentation**: <a href="https://flask-rmq.rdd-lab.com/" target="_blank">https://flask-rmq.rdd-lab.com/</a>

**Source Code**: <a href="https://github.com/RDDLab/Flask-RMQ" target="_blank">https://github.com/RDDLab/Flask-RMQ</a>

---

# 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:

```bash
pip install Flask-RMQ
```

Prometheus support is optional:

```bash
pip install 'Flask-RMQ[metrics]'
```

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

## Minimal application

```python
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
```

```bash
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:

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

The complete runnable producer/consumer project is available in [`examples/basic_app`](examples/basic_app).

## Tests

```bash
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.

```bash
npm install
npm run docs:dev
npm run docs:build
```

MIT licensed.
