Integrate Flask with Faust Integrate Flask with Faust flask flask

Integrate Flask with Faust


You can try to monkeypatch your flask application with gevent or eventlet. As far as I know eventlet is the only one which is currently working since the bridge aiogevent is no longer available in pip.

Another approach is to delegate your Flask app to only produce messages with pykafka or kafka-python. In this way you will keep both applications isolated, flask producing and faust consuming. Note that by default faust will try to create topics without internal flag with 1 replica and internal topics with 8 replicas.


The faust docs have a suggestion for integrating flask and faust. It involves using gevent, but I do not believe it requires monkeypatching.

From the docs (https://faust.readthedocs.io/en/latest/faq.html):

This approach works with any blocking Python library that can work with gevent.Using gevent requires you to install the aiogevent module, and you can install this as a bundle with Faust:$ pip install -U faust[gevent]Then to actually use gevent as the event loop you have to either use the -L option to the faust program:$ faust -L gevent -A myproj worker -l infoor add import mode.loop.gevent at the top of your entry point script:#!/usr/bin/env python3import mode.loop.geventREMEMBER: It’s very important that this is at the very top of the module, and that it executes before you import libraries.