Flask Snippets

Deploying Flask on Cherrypy WSGI server

Posted by esaurito on 2010-05-31 @ 20:52 and filed in Application Structure

CherryPy comes with a WSGI compliant server, so running a Flask application on top of CherryPy is a piece of cake.

Here is the Flask hello world app for reference:

from flask import Flask
app = Flask(__name__)

def hello():
    return "Hello World!"

if __name__ == "__main__":

The following snippet let you run the Flask app on top of the WSGI server shipped with CherryPy.

from cherrypy import wsgiserver
from hello import app

d = wsgiserver.WSGIPathInfoDispatcher({'/': app})
server = wsgiserver.CherryPyWSGIServer(('', 8080), d)

if __name__ == '__main__':
   except KeyboardInterrupt:

You can access the server running on WSGIPathInfoDispatcher take as argument a dictionary mapping a path to an application object, so you can easily deploy multiple (Flask) application on a single CherryPy server.

This snippet by esaurito can be used freely for anything you like. Consider it public domain.