How to implement event handling in Python Flask

Viewed 420

Is there a canonical way in Python, and better yet in Flask, to implement an embedded event handling system?

With event handling, we mean something similar to Symfony's EventDispatcher, which is a simple, embedded system to decouple event dispatch and handling.

The goal is, in a Flask SQLAlchemy API App, to react to creation (or modification) of data objects with creation of additional, derived data objects to maintain a certain sense of consistency. There should be various handlers, each making sure that a certain type of consistency is maintained. These should be separated. It is possible that a handler triggers creation of data, which in turn prompts another handler to create data. This chain should be executed within the context of each request.

These are the options I came across, plus the reasons I ruled them out:

  • Flask signals - discourage us to manipulate data
  • Pyee - this seems closest to what we need, but not sure how well it integrated with Flask
  • Celery - seems more suited for async long running tasks
  • Whistle - one of many shots at the topic that don't seem exceptionally well maintained
  • RabbitMQ, ironMQ or similar - We would like to handle everything within the Flask app
0 Answers
Related