Flask-RMQ 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. flask_rmq-0.1.0/Flask_RMQ.egg-info/PKG-INFO +174 -0
  2. flask_rmq-0.1.0/Flask_RMQ.egg-info/SOURCES.txt +34 -0
  3. flask_rmq-0.1.0/Flask_RMQ.egg-info/dependency_links.txt +1 -0
  4. flask_rmq-0.1.0/Flask_RMQ.egg-info/requires.txt +13 -0
  5. flask_rmq-0.1.0/Flask_RMQ.egg-info/top_level.txt +5 -0
  6. flask_rmq-0.1.0/LICENSE +21 -0
  7. flask_rmq-0.1.0/PKG-INFO +174 -0
  8. flask_rmq-0.1.0/README.md +136 -0
  9. flask_rmq-0.1.0/examples/basic_app/basic_app/__init__.py +3 -0
  10. flask_rmq-0.1.0/examples/basic_app/basic_app/app.py +35 -0
  11. flask_rmq-0.1.0/examples/basic_app/basic_app/messaging.py +48 -0
  12. flask_rmq-0.1.0/examples/basic_app/basic_app/views.py +28 -0
  13. flask_rmq-0.1.0/flask_rmq/__init__.py +28 -0
  14. flask_rmq-0.1.0/flask_rmq/cli.py +111 -0
  15. flask_rmq-0.1.0/flask_rmq/config.py +55 -0
  16. flask_rmq-0.1.0/flask_rmq/connections.py +84 -0
  17. flask_rmq-0.1.0/flask_rmq/consumer.py +137 -0
  18. flask_rmq-0.1.0/flask_rmq/exceptions.py +10 -0
  19. flask_rmq-0.1.0/flask_rmq/extension.py +53 -0
  20. flask_rmq-0.1.0/flask_rmq/observability.py +119 -0
  21. flask_rmq-0.1.0/flask_rmq/producer.py +104 -0
  22. flask_rmq-0.1.0/flask_rmq/py.typed +0 -0
  23. flask_rmq-0.1.0/flask_rmq/queues.py +24 -0
  24. flask_rmq-0.1.0/flask_rmq/registries/__init__.py +4 -0
  25. flask_rmq-0.1.0/flask_rmq/registries/consumers.py +25 -0
  26. flask_rmq-0.1.0/flask_rmq/registries/setup.py +34 -0
  27. flask_rmq-0.1.0/flask_rmq/state.py +62 -0
  28. flask_rmq-0.1.0/pyproject.toml +84 -0
  29. flask_rmq-0.1.0/setup.cfg +4 -0
  30. flask_rmq-0.1.0/tests/conftest.py +13 -0
  31. flask_rmq-0.1.0/tests/test_config.py +24 -0
  32. flask_rmq-0.1.0/tests/test_consumer.py +40 -0
  33. flask_rmq-0.1.0/tests/test_extension.py +28 -0
  34. flask_rmq-0.1.0/tests/test_producer.py +58 -0
  35. flask_rmq-0.1.0/tests/test_queues.py +14 -0
  36. flask_rmq-0.1.0/tests/test_registries.py +22 -0
@@ -0,0 +1,174 @@
1
+ Metadata-Version: 2.4
2
+ Name: Flask-RMQ
3
+ Version: 0.1.0
4
+ Summary: Production-oriented RabbitMQ integration for Flask, built on Pika
5
+ Author: RDD Lab
6
+ License-Expression: MIT
7
+ Project-URL: Documentation, https://flask-rmq.rdd-lab.com/
8
+ Project-URL: Issues, https://github.com/RDDLab/Flask-RMQ/issues
9
+ Project-URL: Repository, https://github.com/RDDLab/Flask-RMQ
10
+ Keywords: flask,rabbitmq,amqp,pika,messaging
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Framework :: Flask
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: Flask<4.0,>=3.0
27
+ Requires-Dist: click>=8.1
28
+ Requires-Dist: pika<2.0,>=1.3.2
29
+ Provides-Extra: metrics
30
+ Requires-Dist: prometheus-client<1.0,>=0.20; extra == "metrics"
31
+ Provides-Extra: dev
32
+ Requires-Dist: build>=1.2; extra == "dev"
33
+ Requires-Dist: mypy>=1.10; extra == "dev"
34
+ Requires-Dist: pytest>=8.0; extra == "dev"
35
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
36
+ Requires-Dist: ruff>=0.9; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ ![Flask-RMQ](docs/.vuepress/public/logo-horizontal.svg)
40
+
41
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
42
+ [![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)
43
+ [![PyPI](https://img.shields.io/pypi/v/Flask-RMQ?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
44
+ [![PyPI pyversions](https://img.shields.io/pypi/pyversions/Flask-RMQ.svg?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
45
+ [![PyPI status](https://img.shields.io/pypi/status/Flask-RMQ.svg?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
46
+ [![PyPI downloads](https://img.shields.io/pypi/dm/Flask-RMQ?style=for-the-badge)](https://pypistats.org/packages/flask-rmq)
47
+ [![PyPI types](https://img.shields.io/pypi/types/Flask-RMQ.svg?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
48
+
49
+ ---
50
+
51
+ [![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/)
52
+ [![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/)
53
+
54
+ ---
55
+
56
+ **Documentation**: <a href="https://flask-rmq.rdd-lab.com/" target="_blank">https://flask-rmq.rdd-lab.com/</a>
57
+
58
+ **Source Code**: <a href="https://github.com/RDDLab/Flask-RMQ" target="_blank">https://github.com/RDDLab/Flask-RMQ</a>
59
+
60
+ ---
61
+
62
+ # Flask-RMQ
63
+
64
+ Flask-RMQ provides typed RabbitMQ wrappers and tools for Flask applications using Pika.
65
+
66
+ 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.
67
+
68
+ Main features:
69
+
70
+ - standard Flask extension and app-factory integration;
71
+ - Click commands under the native `flask rmq` CLI group;
72
+ - separate thread-local producer and consumer connections;
73
+ - publisher confirms, persistent delivery, and `mandatory=True` routing;
74
+ - bounded producer retry and consumer exponential backoff;
75
+ - durable queues and dead-letter routing through `QueueConfig`;
76
+ - per-alias topology and consumer registries;
77
+ - optional Prometheus instrumentation;
78
+ - Python typing with a `py.typed` marker.
79
+
80
+ ## Installation
81
+
82
+ Install Flask-RMQ with pip or your preferred Python package manager:
83
+
84
+ ```bash
85
+ pip install Flask-RMQ
86
+ ```
87
+
88
+ Prometheus support is optional:
89
+
90
+ ```bash
91
+ pip install 'Flask-RMQ[metrics]'
92
+ ```
93
+
94
+ Flask-RMQ supports Python 3.10–3.14 and Flask 3.0–3.1.
95
+
96
+ ## Minimal application
97
+
98
+ ```python
99
+ import json
100
+
101
+ from flask import Flask
102
+ from flask_rmq import (
103
+ Consumer,
104
+ FlaskRMQ,
105
+ Producer,
106
+ get_consumers_registry,
107
+ get_setup_registry,
108
+ )
109
+
110
+ rmq = FlaskRMQ()
111
+ producer = Producer(queue='events')
112
+ consumer = Consumer(queue='events')
113
+
114
+
115
+ @consumer
116
+ def handle_event(channel, method, properties, body: bytes) -> None:
117
+ print(json.loads(body))
118
+ channel.basic_ack(delivery_tag=method.delivery_tag)
119
+
120
+
121
+ def setup_topology(channel) -> None:
122
+ channel.queue_declare(queue='events', durable=True)
123
+
124
+
125
+ def create_app() -> Flask:
126
+ app = Flask(__name__)
127
+ app.config['RABBITMQ_CONNECTIONS'] = {
128
+ 'default': {'HOST': 'localhost'},
129
+ }
130
+ rmq.init_app(app)
131
+ with app.app_context():
132
+ get_setup_registry().register(setup_topology)
133
+ get_consumers_registry().register(consumer)
134
+ return app
135
+ ```
136
+
137
+ ```bash
138
+ flask --app your_app:create_app rmq check
139
+ flask --app your_app:create_app rmq setup
140
+ flask --app your_app:create_app rmq consume
141
+ ```
142
+
143
+ Publish from a Flask route or service:
144
+
145
+ ```python
146
+ producer.publish(json.dumps({'event': 'created'}))
147
+ ```
148
+
149
+ The complete runnable producer/consumer project is available in [`examples/basic_app`](examples/basic_app).
150
+
151
+ ## Tests
152
+
153
+ ```bash
154
+ python -m venv .venv
155
+ . .venv/bin/activate
156
+ pip install -e '.[dev,metrics]'
157
+ pytest
158
+ ruff check .
159
+ python -m build
160
+ ```
161
+
162
+ The unit test suite does not require a live RabbitMQ broker. Use the example project for an end-to-end broker test.
163
+
164
+ ## Documentation portal
165
+
166
+ 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.
167
+
168
+ ```bash
169
+ npm install
170
+ npm run docs:dev
171
+ npm run docs:build
172
+ ```
173
+
174
+ MIT licensed.
@@ -0,0 +1,34 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ Flask_RMQ.egg-info/PKG-INFO
5
+ Flask_RMQ.egg-info/SOURCES.txt
6
+ Flask_RMQ.egg-info/dependency_links.txt
7
+ Flask_RMQ.egg-info/requires.txt
8
+ Flask_RMQ.egg-info/top_level.txt
9
+ examples/basic_app/basic_app/__init__.py
10
+ examples/basic_app/basic_app/app.py
11
+ examples/basic_app/basic_app/messaging.py
12
+ examples/basic_app/basic_app/views.py
13
+ flask_rmq/__init__.py
14
+ flask_rmq/cli.py
15
+ flask_rmq/config.py
16
+ flask_rmq/connections.py
17
+ flask_rmq/consumer.py
18
+ flask_rmq/exceptions.py
19
+ flask_rmq/extension.py
20
+ flask_rmq/observability.py
21
+ flask_rmq/producer.py
22
+ flask_rmq/py.typed
23
+ flask_rmq/queues.py
24
+ flask_rmq/state.py
25
+ flask_rmq/registries/__init__.py
26
+ flask_rmq/registries/consumers.py
27
+ flask_rmq/registries/setup.py
28
+ tests/conftest.py
29
+ tests/test_config.py
30
+ tests/test_consumer.py
31
+ tests/test_extension.py
32
+ tests/test_producer.py
33
+ tests/test_queues.py
34
+ tests/test_registries.py
@@ -0,0 +1,13 @@
1
+ Flask<4.0,>=3.0
2
+ click>=8.1
3
+ pika<2.0,>=1.3.2
4
+
5
+ [dev]
6
+ build>=1.2
7
+ mypy>=1.10
8
+ pytest>=8.0
9
+ pytest-cov>=5.0
10
+ ruff>=0.9
11
+
12
+ [metrics]
13
+ prometheus-client<1.0,>=0.20
@@ -0,0 +1,5 @@
1
+ dist
2
+ docs
3
+ examples
4
+ flask_rmq
5
+ tests
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 RDD Lab
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,174 @@
1
+ Metadata-Version: 2.4
2
+ Name: Flask-RMQ
3
+ Version: 0.1.0
4
+ Summary: Production-oriented RabbitMQ integration for Flask, built on Pika
5
+ Author: RDD Lab
6
+ License-Expression: MIT
7
+ Project-URL: Documentation, https://flask-rmq.rdd-lab.com/
8
+ Project-URL: Issues, https://github.com/RDDLab/Flask-RMQ/issues
9
+ Project-URL: Repository, https://github.com/RDDLab/Flask-RMQ
10
+ Keywords: flask,rabbitmq,amqp,pika,messaging
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Framework :: Flask
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3 :: Only
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Programming Language :: Python :: 3.13
20
+ Classifier: Programming Language :: Python :: 3.14
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Classifier: Typing :: Typed
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: Flask<4.0,>=3.0
27
+ Requires-Dist: click>=8.1
28
+ Requires-Dist: pika<2.0,>=1.3.2
29
+ Provides-Extra: metrics
30
+ Requires-Dist: prometheus-client<1.0,>=0.20; extra == "metrics"
31
+ Provides-Extra: dev
32
+ Requires-Dist: build>=1.2; extra == "dev"
33
+ Requires-Dist: mypy>=1.10; extra == "dev"
34
+ Requires-Dist: pytest>=8.0; extra == "dev"
35
+ Requires-Dist: pytest-cov>=5.0; extra == "dev"
36
+ Requires-Dist: ruff>=0.9; extra == "dev"
37
+ Dynamic: license-file
38
+
39
+ ![Flask-RMQ](docs/.vuepress/public/logo-horizontal.svg)
40
+
41
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
42
+ [![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)
43
+ [![PyPI](https://img.shields.io/pypi/v/Flask-RMQ?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
44
+ [![PyPI pyversions](https://img.shields.io/pypi/pyversions/Flask-RMQ.svg?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
45
+ [![PyPI status](https://img.shields.io/pypi/status/Flask-RMQ.svg?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
46
+ [![PyPI downloads](https://img.shields.io/pypi/dm/Flask-RMQ?style=for-the-badge)](https://pypistats.org/packages/flask-rmq)
47
+ [![PyPI types](https://img.shields.io/pypi/types/Flask-RMQ.svg?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
48
+
49
+ ---
50
+
51
+ [![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/)
52
+ [![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/)
53
+
54
+ ---
55
+
56
+ **Documentation**: <a href="https://flask-rmq.rdd-lab.com/" target="_blank">https://flask-rmq.rdd-lab.com/</a>
57
+
58
+ **Source Code**: <a href="https://github.com/RDDLab/Flask-RMQ" target="_blank">https://github.com/RDDLab/Flask-RMQ</a>
59
+
60
+ ---
61
+
62
+ # Flask-RMQ
63
+
64
+ Flask-RMQ provides typed RabbitMQ wrappers and tools for Flask applications using Pika.
65
+
66
+ 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.
67
+
68
+ Main features:
69
+
70
+ - standard Flask extension and app-factory integration;
71
+ - Click commands under the native `flask rmq` CLI group;
72
+ - separate thread-local producer and consumer connections;
73
+ - publisher confirms, persistent delivery, and `mandatory=True` routing;
74
+ - bounded producer retry and consumer exponential backoff;
75
+ - durable queues and dead-letter routing through `QueueConfig`;
76
+ - per-alias topology and consumer registries;
77
+ - optional Prometheus instrumentation;
78
+ - Python typing with a `py.typed` marker.
79
+
80
+ ## Installation
81
+
82
+ Install Flask-RMQ with pip or your preferred Python package manager:
83
+
84
+ ```bash
85
+ pip install Flask-RMQ
86
+ ```
87
+
88
+ Prometheus support is optional:
89
+
90
+ ```bash
91
+ pip install 'Flask-RMQ[metrics]'
92
+ ```
93
+
94
+ Flask-RMQ supports Python 3.10–3.14 and Flask 3.0–3.1.
95
+
96
+ ## Minimal application
97
+
98
+ ```python
99
+ import json
100
+
101
+ from flask import Flask
102
+ from flask_rmq import (
103
+ Consumer,
104
+ FlaskRMQ,
105
+ Producer,
106
+ get_consumers_registry,
107
+ get_setup_registry,
108
+ )
109
+
110
+ rmq = FlaskRMQ()
111
+ producer = Producer(queue='events')
112
+ consumer = Consumer(queue='events')
113
+
114
+
115
+ @consumer
116
+ def handle_event(channel, method, properties, body: bytes) -> None:
117
+ print(json.loads(body))
118
+ channel.basic_ack(delivery_tag=method.delivery_tag)
119
+
120
+
121
+ def setup_topology(channel) -> None:
122
+ channel.queue_declare(queue='events', durable=True)
123
+
124
+
125
+ def create_app() -> Flask:
126
+ app = Flask(__name__)
127
+ app.config['RABBITMQ_CONNECTIONS'] = {
128
+ 'default': {'HOST': 'localhost'},
129
+ }
130
+ rmq.init_app(app)
131
+ with app.app_context():
132
+ get_setup_registry().register(setup_topology)
133
+ get_consumers_registry().register(consumer)
134
+ return app
135
+ ```
136
+
137
+ ```bash
138
+ flask --app your_app:create_app rmq check
139
+ flask --app your_app:create_app rmq setup
140
+ flask --app your_app:create_app rmq consume
141
+ ```
142
+
143
+ Publish from a Flask route or service:
144
+
145
+ ```python
146
+ producer.publish(json.dumps({'event': 'created'}))
147
+ ```
148
+
149
+ The complete runnable producer/consumer project is available in [`examples/basic_app`](examples/basic_app).
150
+
151
+ ## Tests
152
+
153
+ ```bash
154
+ python -m venv .venv
155
+ . .venv/bin/activate
156
+ pip install -e '.[dev,metrics]'
157
+ pytest
158
+ ruff check .
159
+ python -m build
160
+ ```
161
+
162
+ The unit test suite does not require a live RabbitMQ broker. Use the example project for an end-to-end broker test.
163
+
164
+ ## Documentation portal
165
+
166
+ 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.
167
+
168
+ ```bash
169
+ npm install
170
+ npm run docs:dev
171
+ npm run docs:build
172
+ ```
173
+
174
+ MIT licensed.
@@ -0,0 +1,136 @@
1
+ ![Flask-RMQ](docs/.vuepress/public/logo-horizontal.svg)
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
4
+ [![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)
5
+ [![PyPI](https://img.shields.io/pypi/v/Flask-RMQ?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
6
+ [![PyPI pyversions](https://img.shields.io/pypi/pyversions/Flask-RMQ.svg?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
7
+ [![PyPI status](https://img.shields.io/pypi/status/Flask-RMQ.svg?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
8
+ [![PyPI downloads](https://img.shields.io/pypi/dm/Flask-RMQ?style=for-the-badge)](https://pypistats.org/packages/flask-rmq)
9
+ [![PyPI types](https://img.shields.io/pypi/types/Flask-RMQ.svg?style=for-the-badge)](https://pypi.org/project/Flask-RMQ/)
10
+
11
+ ---
12
+
13
+ [![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/)
14
+ [![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/)
15
+
16
+ ---
17
+
18
+ **Documentation**: <a href="https://flask-rmq.rdd-lab.com/" target="_blank">https://flask-rmq.rdd-lab.com/</a>
19
+
20
+ **Source Code**: <a href="https://github.com/RDDLab/Flask-RMQ" target="_blank">https://github.com/RDDLab/Flask-RMQ</a>
21
+
22
+ ---
23
+
24
+ # Flask-RMQ
25
+
26
+ Flask-RMQ provides typed RabbitMQ wrappers and tools for Flask applications using Pika.
27
+
28
+ 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.
29
+
30
+ Main features:
31
+
32
+ - standard Flask extension and app-factory integration;
33
+ - Click commands under the native `flask rmq` CLI group;
34
+ - separate thread-local producer and consumer connections;
35
+ - publisher confirms, persistent delivery, and `mandatory=True` routing;
36
+ - bounded producer retry and consumer exponential backoff;
37
+ - durable queues and dead-letter routing through `QueueConfig`;
38
+ - per-alias topology and consumer registries;
39
+ - optional Prometheus instrumentation;
40
+ - Python typing with a `py.typed` marker.
41
+
42
+ ## Installation
43
+
44
+ Install Flask-RMQ with pip or your preferred Python package manager:
45
+
46
+ ```bash
47
+ pip install Flask-RMQ
48
+ ```
49
+
50
+ Prometheus support is optional:
51
+
52
+ ```bash
53
+ pip install 'Flask-RMQ[metrics]'
54
+ ```
55
+
56
+ Flask-RMQ supports Python 3.10–3.14 and Flask 3.0–3.1.
57
+
58
+ ## Minimal application
59
+
60
+ ```python
61
+ import json
62
+
63
+ from flask import Flask
64
+ from flask_rmq import (
65
+ Consumer,
66
+ FlaskRMQ,
67
+ Producer,
68
+ get_consumers_registry,
69
+ get_setup_registry,
70
+ )
71
+
72
+ rmq = FlaskRMQ()
73
+ producer = Producer(queue='events')
74
+ consumer = Consumer(queue='events')
75
+
76
+
77
+ @consumer
78
+ def handle_event(channel, method, properties, body: bytes) -> None:
79
+ print(json.loads(body))
80
+ channel.basic_ack(delivery_tag=method.delivery_tag)
81
+
82
+
83
+ def setup_topology(channel) -> None:
84
+ channel.queue_declare(queue='events', durable=True)
85
+
86
+
87
+ def create_app() -> Flask:
88
+ app = Flask(__name__)
89
+ app.config['RABBITMQ_CONNECTIONS'] = {
90
+ 'default': {'HOST': 'localhost'},
91
+ }
92
+ rmq.init_app(app)
93
+ with app.app_context():
94
+ get_setup_registry().register(setup_topology)
95
+ get_consumers_registry().register(consumer)
96
+ return app
97
+ ```
98
+
99
+ ```bash
100
+ flask --app your_app:create_app rmq check
101
+ flask --app your_app:create_app rmq setup
102
+ flask --app your_app:create_app rmq consume
103
+ ```
104
+
105
+ Publish from a Flask route or service:
106
+
107
+ ```python
108
+ producer.publish(json.dumps({'event': 'created'}))
109
+ ```
110
+
111
+ The complete runnable producer/consumer project is available in [`examples/basic_app`](examples/basic_app).
112
+
113
+ ## Tests
114
+
115
+ ```bash
116
+ python -m venv .venv
117
+ . .venv/bin/activate
118
+ pip install -e '.[dev,metrics]'
119
+ pytest
120
+ ruff check .
121
+ python -m build
122
+ ```
123
+
124
+ The unit test suite does not require a live RabbitMQ broker. Use the example project for an end-to-end broker test.
125
+
126
+ ## Documentation portal
127
+
128
+ 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.
129
+
130
+ ```bash
131
+ npm install
132
+ npm run docs:dev
133
+ npm run docs:build
134
+ ```
135
+
136
+ MIT licensed.
@@ -0,0 +1,3 @@
1
+ from .app import create_app
2
+
3
+ __all__ = ['create_app']
@@ -0,0 +1,35 @@
1
+ from __future__ import annotations
2
+
3
+ import os
4
+
5
+ from flask import Flask
6
+
7
+ from flask_rmq import FlaskRMQ
8
+
9
+ from .messaging import register_messaging
10
+ from .views import api
11
+
12
+ rmq = FlaskRMQ()
13
+
14
+
15
+ def create_app() -> Flask:
16
+ app = Flask(__name__)
17
+ app.config['RABBITMQ_CONNECTIONS'] = {
18
+ 'default': {
19
+ 'HOST': os.getenv('RABBITMQ_HOST', 'localhost'),
20
+ 'PORT': int(os.getenv('RABBITMQ_PORT', '5672')),
21
+ 'VIRTUAL_HOST': os.getenv('RABBITMQ_VHOST', '/'),
22
+ 'USER': os.getenv('RABBITMQ_USER', 'guest'),
23
+ 'PASSWORD': os.getenv('RABBITMQ_PASSWORD', 'guest'),
24
+ 'HEARTBEAT': 60,
25
+ 'BLOCKED_CONNECTION_TIMEOUT': 30,
26
+ 'RECONNECT_INITIAL_BACKOFF': 1,
27
+ 'RECONNECT_MAX_BACKOFF': 15,
28
+ }
29
+ }
30
+ app.config['CONSUMED_FILE'] = os.getenv('CONSUMED_FILE', 'consumed.jsonl')
31
+ rmq.init_app(app)
32
+ app.register_blueprint(api)
33
+ with app.app_context():
34
+ register_messaging()
35
+ return app
@@ -0,0 +1,48 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+
5
+ from flask import current_app
6
+ from pika.adapters.blocking_connection import BlockingChannel
7
+
8
+ from flask_rmq import Consumer, Producer, QueueConfig, get_consumers_registry, get_setup_registry
9
+
10
+ EVENTS_QUEUE = QueueConfig(
11
+ name='flask_rmq.events',
12
+ durable=True,
13
+ dead_letter_exchange='flask_rmq.dlx',
14
+ dead_letter_routing_key='flask_rmq.events.failed',
15
+ )
16
+ producer = Producer(exchange='flask_rmq.events', queue=EVENTS_QUEUE)
17
+ consumer = Consumer(queue=EVENTS_QUEUE)
18
+
19
+
20
+ def setup_topology(channel: BlockingChannel) -> None:
21
+ channel.exchange_declare(exchange='flask_rmq.events', exchange_type='direct', durable=True)
22
+ channel.exchange_declare(exchange='flask_rmq.dlx', exchange_type='direct', durable=True)
23
+ channel.queue_declare(queue=EVENTS_QUEUE.name, durable=True, arguments=EVENTS_QUEUE.arguments)
24
+ channel.queue_bind(
25
+ exchange='flask_rmq.events',
26
+ queue=EVENTS_QUEUE.name,
27
+ routing_key=EVENTS_QUEUE.name,
28
+ )
29
+ channel.queue_declare(queue='flask_rmq.events.failed', durable=True)
30
+ channel.queue_bind(
31
+ exchange='flask_rmq.dlx',
32
+ queue='flask_rmq.events.failed',
33
+ routing_key='flask_rmq.events.failed',
34
+ )
35
+
36
+
37
+ @consumer
38
+ def save_event(channel, method, properties, body: bytes) -> None:
39
+ output = Path(current_app.config['CONSUMED_FILE'])
40
+ with output.open('ab') as stream:
41
+ stream.write(body + b'\n')
42
+ current_app.logger.info('Consumed: %s', body.decode('utf-8'))
43
+ channel.basic_ack(delivery_tag=method.delivery_tag)
44
+
45
+
46
+ def register_messaging() -> None:
47
+ get_setup_registry().register(setup_topology)
48
+ get_consumers_registry().register(consumer)
@@ -0,0 +1,28 @@
1
+ from __future__ import annotations
2
+
3
+ import json
4
+ from datetime import UTC, datetime
5
+ from uuid import uuid4
6
+
7
+ from flask import Blueprint, jsonify, request
8
+
9
+ from .messaging import producer
10
+
11
+ api = Blueprint('api', __name__)
12
+
13
+
14
+ @api.get('/health')
15
+ def health():
16
+ return {'status': 'ok'}
17
+
18
+
19
+ @api.post('/events')
20
+ def publish_event():
21
+ incoming = request.get_json(silent=True) or {}
22
+ event = {
23
+ 'id': str(uuid4()),
24
+ 'created_at': datetime.now(UTC).isoformat(),
25
+ 'payload': incoming,
26
+ }
27
+ producer.publish(json.dumps(event))
28
+ return jsonify(event), 202