title: Send console data to flask App to display on the client
body: <p>I'm trying to use a javascript plotting library to plot data I calculated in the python console (IPython) using Numpy.</p>
  
  <p>I was thinking of a design to accomplish this. I thought it should look something like this:</p>
  
  <p><img src="https://i.stack.imgur.com/DSHFN.jpg" alt="enter image description here"></p>
  
  <p>This means I'm using a Flask app to sent a server-side event to the client as soon as the data is ready in the IPython process.</p>
  
  <p>1) Is this the right approach?</p>
  
  <p>2) How can I send data from the console to my Flask app? I think I need to run the Flask App with gevent so I can listen to commands from the other python process?</p>
  
  <p>3) How can I send the data using a server-side event to the client? I found some examples of server-side events but I don't see how they can sent arbitrary data. Example:</p>
  
  <pre><code>import gevent
  import gevent.monkey
  from gevent.pywsgi import WSGIServer
  gevent.monkey.patch_all()
  
  from flask import Flask, request, Response, render_template
  
  app = Flask(__name__)
  
  def event_stream():
      count = 0
      while True:
          gevent.sleep(2)
          yield 'data: %s\n\n' % count
          count += 1
  
  @app.route('/my_event_source')
  def sse_request():
      return Response(
              event_stream(),
              mimetype='text/event-stream')
  
  @app.route('/')
  def page():
      return render_template('sse.html')
  
  if __name__ == '__main__':
      http_server = WSGIServer(('127.0.0.1', 8001), app)
      http_server.serve_forever()
  </code></pre>
  
  <p>This example uses a predefined event_stream() function. I am looking for a way to send the data from the python console with a server-side event to the client.</p>
  
  <p>Maybe there is another and better approach?</p>