Can push notifications be done with an AngularJS+Flask stack?

I have a Python/Flask backend and an Angular frontend for my website. At the backend there is a process that occasionally checks SQS for messages and I want it to push a notification to the client which can then in turn update an Angular controller. What is the best way to do this my existing technologies?

Best answer

To be able to push to the client, you’ll have to implement web socket support in some fashion. If you want to keep it in python/flask, there is this tutorial on how to do that with gevent:

http://www.socketubs.org/2012/10/28/Websocket_with_flask_and_gevent.html

In that article, Geoffrey also mentions a SocketIO compatible library for python/gevent that may allow you to leverage the SocketIO client-side JS library, called “gevent-socketio”.

That may reduce how much work you have to do in terms of cross-browser compatibility since SocketIO has done a lot of that already.

Here is a pretty good tutorial on how to use SocketIO in AngularJS so that you can notify the AngularJS model when an event comes in from SocketIO:

http://www.html5rocks.com/en/tutorials/frameworks/angular-websockets/

If you don’t want to host the web socket backend, you could look to a hosted service like PubNub or Pusher and then integrate them into AngularJS as a service. You can communicate with these services through your Python app (when the SQS notification happens) and they’ll notify all connected clients for you.