Twisted: an event-driven server for Python

posted in: Uncategorized | 0
[Edited August 24, 2012]

I attended an introduction to Twister, a Python asynchronous engine, on July 13, 2012, at Rackspace’s new office. This asynchronous engine is a modular library that allows different types of processes to perform non-block operations such as handling network traffic, running web pages, hosting IRC channels, and running a DNS server. Its nearest and most advertised equivalent is Node.js on the Javascript language. Unlike Node.js Twister has been around for around 10 years and the Python language 20 years. Originally developed by Cliff, a team of experienced developers including people at Rackspace maintain the code base and migrate it to the new Python 3 language.

Twister is designed such that code is written as functions that respond to events happening. It is a low-layer library, which does not provide web framework functionality. It cannot be compared to Django or Ruby on Rails, see previous blog post.

Although Twisted provides functionality to serve web pages, apache is a better web server and bind is a better DNS server. Twisted’s selling feature is interconnecting these functions in a single process because of Twisted’s modular architecture. Other servers built ground up from C and have their own idiosyncratic connections.

Some of Twisted’s functionality are listed below.

Web Server


wsgi – standard python interface

twistd = wsgi container

IRC Channel

SSL can be used instead of TCP.

DNS Server


Mail Server

TCP Write Back Example

This example writes the same TCP stream back as it is received.



To ensure that twisted is installed correctly, the following unit tests are run:

trial twisted