An OpenShift cartridge which adds support for various python web servers
Python Shell HTML
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.

OpenShift Advanced Python Cartridge

Inspired by the Advanced Ruby Cartridge this cartridge attempts to add support for the various WSGI-compliant python servers to the OpenShift platform. It does this by combining a modified python cartridge with the downloadable Nginx cartridge as a reverse proxy.


The official python cartridge uses Apache and mod_wsgi to serve your app which isn't asynchronous and presents a problem for websockets. An alternative is to provide an file which allows you to avoid mod_wsgi and use something like gevent, but that elimintates the ability to serve static files through a fast webserver like Apache or Nginx.


To install this cartridge use the cartridge reflector when creating an app

rhc create-app myapp


Using the cartridge isn't very different to the official python cartridge. Instead of providing a WSGI application() function at wsgi/application you instead provide the application() function at This file will be used directly by all the available servers.

By default wsgiref is used so a working environment can be provided immediately. This is easily changed by setting the OPENSHIFT_PYTHON_SERVER environment variable and then restarting or redeploying the app.

rhc env set OPENSHIFT_PYTHON_SERVER=gunicorn
rhc app restart

Be aware, however, that restarting/redeploying after changing servers for the first time might take a fair amount of time. This is because the server packages get compiled and installed on an as needed basis. Gevent and Gunicorn (which is configured to use gevent as its workers), for example, needs to be compiled within the app as OpenShift doesn't provide it as a system level package.

Supported servers

  • wsgiref
  • gevent
  • gunicorn


There is little to no configuration required as most of the details lay in the interaction between Nginx and the WSGI server package. All that is required is to define the application() function in Any configuration for the server package will be exposed via environment variables.

Environment Variables

OPENSHIFT_PYTHON_WORKERS - The number of workers to spawn for packages like gunicorn. Default: number of CPUs * 2 + 1

Static files

Static files will be served from the public/ directory. These files will be served directly by Nginx.

Web Sockets

Web socket support is enabled in Nginx, however it does little more than passing the requests through with the appropriate upgrade headers. More complex websocket environments will need to go for the customised nginx.conf option.

In the future there might be a nicer way to support websockets as a completely separate server. For example, the application might be served out by gunicorn, but websocket services served out with twisted or tornado. These are purely thoughts at the moment however.

Custom nginx.conf

Like the standalone Nginx cartridge, its possible to provide your own server configuration to be included in the main nginx.conf file. A sample is provided in the cloned repo as nginx.conf.erb.sample. Simply remove the .sample suffix and commit the changes.nginx.conf.erb will be processed and included in the main configuration every time the server starts.