When to use Tornado, when to use Twisted / Cyclone / GEvent / other [closed]

"Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design". If you are building something that is similar to a e-commerce site, then you should probably go with Django. It will get your work done quick. You dont have to worry about too many technology choices. It provides everything thing you need from template engine to ORM. It will be slightly opinionated about the way you structure your app, which is good If you ask me. And it has the strongest community of all the other libraries, which means easy help is available.

"Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions". Beware - "microframework" may be misleading. This does not mean that Flask is a half-baked library. This mean the core of flask is very, very simple. Unlike Django, It will not make any Technology decisions for you. You are free to choose any template engine or ORM that pleases you. Even though it comes with Jinja template engine by default, you are always free to choose our own. As far as I know Flask comes in handy for writing APIs endpoints (RESTful services).

"Twisted is an event-driven networking engine written in python". This is a high-performance engine. The main reason for its speed is something called as deferred. Twisted is built on top of deferreds. For those of you who dont know about defereds, it is the mechanism through with asynchronous architecture is achieved. Twisted is very fast. But is not suitable for writing conventional webapps. If you want to do something low-level networking stuff, twisted is your friend.

"Tornado is a Python web framework and asynchronous networking library, originally developed at FriendFeed. By using non-blocking network I/O, Tornado can scale to tens of thousands of open connections, making it ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user". Tornado stands some where between Django and Flask. If you want to write something with Django or Flask, but if you need a better performance, you can opt for Tornado. it can handle C10k problem very well if it is architected right.

"Cyclone is a web server framework for Python that implements the Tornado API as a Twisted protocol". Now, what if you want something that is nearly as performant as Twisted but easy to write conventional webapps? Say hello to cyclone. I would prefer Cyclone over Tornado. It has an API that is very similar to Tornado. As a matter of fact, this is a fork of Tornado. But the problem is it has relativly small community. Alexandre Fiori is the only main commiter to the repo.

"Pyramid is a general, open source, Python web application development framework. Its primary goal is to make it easier for a Python developer to create web applications." I haven't really used Pyramid, but I went through the documentation. From what I understand, Pyramid is very similar to Flask and I think you can use Pyramid wherever Flask seems appropriate and vice-versa.

EDIT: Request to review any other frameworks are welcomed!

Source: http://dhilipsiva.com/2013/05/19/python-libraries-django-twisted-tornado-flask-cyclone-and-pyramid.html


This is obviously a somewhat biased answer, but that is not the same thing as a wrong answer; you should always use Twisted. I've answered similar questions before, but since your question is not quite the same, here are some reasons:

"Best Performance"

Twisted continuously monitors our performance at the speed.twistedmatrix.com website. We were also one of the first projects to be monitored by PyPy's similar site, thereby assuring the good performance of Twisted on the runtime that anyone concerned with high-performance applications in Python.

"Scalability"

To my knowledge, none of the listed frameworks have any built-in support for automatic scaling; they're all communication frameworks, so you have to do the work to communicate between your scaling nodes. However, Twisted has an advantage in its built-in support for local multi-processing. In fairness, there is a third-party add-on for Tornado that allows you to do the same thing. In recent releases, Twisted has added features that increase the number of ways you can share work between cores, and work is ongoing in that area. Twisted also has a couple of well-integrated, "native" RPC protocols which offer a construction-kit for whatever scaling idiom you want to pursue.

"Most Useful"

Lots of people seem to find Twisted very useful. So much so that many of them have extended it and made their extensions available to you.

"Functionality"

Out of the box, Twisted includes:

  • good support for test-driven development of all the following
  • TCP servers, clients, transport layer security
  • SSH client and server
  • IMAP4, ESMTP, POP3 clients and servers
  • DNS client and server
  • HTTP client and server
  • IRC, XMPP, OSCAR, MSN clients and servers

In this last department, at least, Twisted seems a clear winner for built-in functionality. And all this, in a package just over 2 megabytes!


I like @Glyph response. Twisted is very comprehensive, rich python framework. Twisted and Tornado have a very similar design. And I like this design very much:

  • it's fast
  • easy to understand
  • easy to extend
  • doesn't require c-extensions
  • works on PyPy.

But I want to highlight Tornado, which I prefer and recently gain popularity. Tornado, like Twisted, uses callback style programming, but it can be inlined using tornado.gen.engine (twisted.internet.inlineCallbacks in Twisted).

Codebase

The best comment is from http://cyclone.io site. cyclone tries to mix Twisted and Tornado because:

Twisted is one of the most mature libraries for non-blocking I/O available to the public. Tornado is the open source version of FriendFeed’s web server, one of the most popular and fast web servers for Python, with a very decent API for building web applications.

The idea is to bridge Tornado's elegant and straightforward API to Twisted's Event-Loop, enabling a vast number of supported protocols.

But in 2011 tornado.platform.twisted was out which brings similar functionality.

Performance

Tornado has much better performance. It also works seamlessly with PyPy, and get huge gain.

Scalability

The same like Twisted. Tornado has tornado.process and a lot of rpc services implemented on top of it.

Functionality

There are 71 Tornado based package, compared to 148 Twisted's and 48 Gevent's. But if you look carefully and compute median of packages upload time, you will see that Twisted ones are the oldest, then Gevent and Tornado the freshest. Furthermore there is tornado.platform.twisted module which allows you to run code written for Twisted on Tornado.

Summary

With Tornado you can use a code from Twisted. There is no need to use cyclone which only twists your code (your code becomes more messy).

As for 2014, Tornado is considered as widely accepted and default async framework which works both on python2 and python3. Also the latest version 4.x brings a lot of functionality from https://docs.python.org/dev/library/asyncio.html.

I wrote an article, explaining why I consider that Tornado - the best Python web framework where I wrote much more about Tornado functionality.