Python web servers

Subscribe to our

There are several Python-based web servers available for use. Each of them has some particular advantages, specific features and levels of scalability, robustness and convenience. In this article, we examine several open source web servers written in Python. They are: Gunicorn, Twisted Web, Chaussette, as well as WSGI servers from Tornado, CherryPy, and Waitress.

Gunicorn

Gunicorn Python web serverGunicorn is a stand-alone web server with clear architecture and native support for WSGI, Django, and Paster. It is compatible with any Python application and framework that runs on WSGI. Gunicorn features pre-fork model, SSL support, automatic worker process management and several worker types/configurations that can be adapted to suit various production scenarios. HTTP/1.0 and HTTP/1.1 are supported via synchronous and asynchronous workers. Regardless the piling of functionality, Gunicorn is significantly easy to implement and operate. Moreover, it can be extended with various server hooks.

Twisted Web

Twisted Web Python web serverWhile Twisted is an event-driven networking engine, Twisted Web is an HTTP server that can be used as ​a library or run as a stand-alone WSGI server. It can power any web applications based on Python and even other programming languages like Perl, PHP, etc. via twisted.web.twcgi API. Twisted Web has a lot of built-in functionality, including support for name-based virtual hosts, local multi-processing, proxy and reverse-proxy capabilities, XML parsing, prototyping, and well-integrated RPC protocols that will simplify scaling. Apart from HTTP it supports such clients and servers as TCP, SSH, DNS, IMAP4, ESMTP, POP3, IRC, XMPP, OSCAR, and MSN. Twisted Web is a simple to use, fast and mature product.

Tornado WSGI server

Tornado Python web serverTornado is a Python web framework and asynchronous networking library that offers a WSGI server for WSGI Python applications and frameworks to run on. Tornado features non-blocking network I/O that helps to scale really well on an increased concurrency. The framework is perfect to dealing with real-time services that require a long-lived connection to each user, like long polling, HTTP streaming, and WebSockets. Tornado has built-in support for such cumbersome aspects of web development as user authentication, cross-site request forgery protection, signed cookies, aggressive static file caching, and third party authentication.

CherryPy WSGI Server

CherryPy Python web serverCherryPy is a fast, stable and fully self-contained web framework. It features a reliable, HTTP/1.1-compliant, web server that can serve any Python application running on WSGI, not necessarily bound to CherryPy. This build-in HTTP server comes with support for SSL and is thread-pooled. It is easy to run multiple HTTP servers at once, for example, on multiple ports. CherryPy WSGI Server is great for production ready deployments, specifically for apps deployed on Windows, stand alone, intranets, low and middle traffic websites.

Waitress WSGI Server

Waitress is a lean, production-quality pure-Python WSGI server. It supports both HTTP/1.0 and HTTP/1.1, as well as WSGI file_wrapper protocol. What really sets Waitress aside is its development philosophy that aims at neutralizing issues caused by differences between platforms, interpreters and Python versions. As a result, Waitress works on Windows and Unix, runs on CPython and PyPy, and supports both Python 2 and 3. This web server can be used behind a (reverse) proxy. It is very easy configuration with acceptable performance. Waitress really is framework-independent in its nature. Although there is lack of native SSL support, command-line runner allows running WSGI applications without any additional machinery.

Chaussette

Chaussette is a WSGI server that can run a plain WSGI application, a Django application, or a Paste application. It can not only bind a socket on a port (like any other server), but also run against already opened sockets. Chaussette does not provide advanced features, such as multi-threading or multi-processing. Instead it focuses on serving requests and delegates process and socket management to other tools like Circus and Supervisor. They take care of binding the socket and spawning Chaussette processes. Basically Chaussette is just a bit of glue between the existing WSGI servers and back ends. It is a pure Python implementation based on wsgiref, but it can work with other efficient back ends, including gevent, meinheld, waitress, eventlet, socketio, bjoern, tornado, etc.

Follow