Demo program using flask-socketIO: Scroll Down for Details
HTML Python Shell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Websockets in Flask on Heroku

Flask powered
(With inspiration from

Note: this example is taken directly from Miguel Grinberg's example. It required slight adaptation (see notes). The goal was just to get it going, and then see if it could be launched on Heroku.

Some of the libraries involved here are only for Python 2.7, so you must first install that version of Python.

Although the most recent versions of Python do install pip, for some reason it's an old version. To get the latest version of pip:

python -m pip install -U pip

Next, make sure you have virtualenv installed:

virtualenv --version

If this gives you an error message, run:

pip install virtualenv

Quick Start on Windows

(Tested on Windows 7 and Windows 8).

To experiment locally on Windows (before deploying on Heroku) I've gone through the various thrashings-around and tried to capture and simplify things.

Flask-SocketIO relies on gevent which in turn relies on greenlet, both of which are binaries. You can figure out how to install the right Microsoft Visual C++ Compiler and configure it so that you don't get the message about not finding vcvarsall.bat file, but I couldn't figure that out and I eventually discovered that I could install directly from the wheel files. I've included the necessary wheel files in this distribution, and you'll see that in setup2.bat the pip commands that directly install the wheel files precede the pip install using requirements.txt. This seems to work (but note that my particular wheel files might be out of date when you read this).

Now, for your local Windows testing you should be able to run:


And then be ready to start the app:


If that succeeds, you should be able to open a local page and see the results.

The go.bat and bye.bat allow you to quickly enter and leave the virtualenv.

The Heroku deploy ignores the .bat files and just uses the requirements.txt which does the normal builds (using Heroku's C++ compiler).

Run Locally on Mac/Linux

  1. Setup virtualenv

     virtualenv venv --distribute
  2. Activate virtualenv:

     source venv/bin/activate
  3. Get the dependencies:

     pip install -r requirements.txt
  4. Start Flask Server

  5. Test out the app by opening a local page to see the results.

Run on Heroku

  1. Create the app

     heroku create -s cedar
  2. Deploy the app

     git push heroku master
  3. Open the app in your browser

     heroku open

Nicer alternative:

Log onto the Heroku dashboard, then follow the instructions to connect to your github repository and launch your app. This can include auto-deployment every time you update your Github repository!