2

I'm having a problem in implementing an application using the Flask framework to send real-time data to a client browser. It will be streaming tweet user info to a client, using the twitter Streaming API(tweepy). Tweet information is also stored into a mongo DB, for future retrieval.

I assume this has to involve long-polling/ server side events(SSEs), which Flask doesn't seem to handle with ease. Juggernaut doesn't do it and is now deprecated in favour of SSEs.

Would Tornado be more suitable if I wanted to send real-time data to a client, or are there more appropriate web frameworks.

I am fairly new to python and it's the first time I'm trying to do this.

Thanks

user94628
  • 3,641
  • 17
  • 51
  • 88

2 Answers2

1

Flask can handle long-polling or events, the main implementation problem is the WSGI server. Here's an example with gevent and websockets: https://gist.github.com/1185629

Martin Samson
  • 3,970
  • 21
  • 25
  • When I try the example in the link it gives me a 500 error. – user94628 Oct 24 '12 at 14:48
  • Possible. The example i linked was just to illustrate how Flask can handle long polling. That GIST was made a year ago, it might not be compatible with your flask version. All that said, it's up to the WSGI server to support long polling / event, not flask. – Martin Samson Oct 24 '12 at 15:05
  • Ok, would it be easier to use tornado which seems to support pushing data from server to client at the outset? – user94628 Oct 24 '12 at 15:38
  • 1
    Another example of Flask, gevent, and gevent-websocket [https://bitbucket.org/jeunice/flask-ws-example](https://bitbucket.org/jeunice/flask-ws-example). Not a Web Sockets masterpiece, as it tries to remain parallel and comparable to my similar example of Flask and long-polling. But it gives the general idea, with a few refinements. – Jonathan Eunice Aug 07 '13 at 01:47
0

You can use websocket witn socket.io and look ath this post about python client library.

Community
  • 1
  • 1
Yohann
  • 6,047
  • 3
  • 26
  • 33