Showing posts with label twisted. Show all posts
Showing posts with label twisted. Show all posts

Sunday, May 19, 2013

Python Libraries: Django, Twisted, Tornado, Flask and Cyclone.

This post will soon be moved here
This blog has moved to http://dhilipsiva.com/blog/

This post is outdated.


NOTE: This post may be modified soon. I suspect that this will start a flamewar. I have written this post as far as I understood these libraries.

I have been writing production applications in python for almost 2 years now. And I have come across quiet a few libraries. I was confused and didn't know what to use at first. So I experimented with as many libraries as possible. So here is what I found until now.


"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 rervices).


"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 somehting 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.

I am working on the tabulation. I ll be updating it as soon as I find time to complete it.

Want me to review any other library? Please leave a comment below.

Comments / Suggestions / Edits welcomed.

Tuesday, September 4, 2012

My first pull request

“A journey of a thousand miles begins with a single step.”

That single step for me, in my carrier, is learning python. A fun loving, magnificent beauty. For me, programming is like raising a baby. Initially, the baby girl doesn’t know anything. As a dad, its my responsibility to teach her what to expect, how to react & what to respond. For me, it is more than art. Its parenting. I take care of her so that, she never crashes. To ensure that she  can be fixed when someone breaks her, I should write great test cases. She is just a kid right? She is not mature enough to take care of her all by herself. So I have to make sure that she is always happy by employing some care taker who always look after her changes. Buildbot is her caretaker. When some one breaks her, buildbot will notify me where I can fix her right away.

So I was trying to get buildbot up and running. For some unknown reasons, it did not start. It just crashed. When I looked at the logs, it said that “twisted.web.errors.NoResource” was missing. Well that was weird. So I decided to go through the source-code of twisted. And “No Resource” was no where to be found. I got confused. Only then I found out that Twisted was updated to 12.2 just a few minutes ago.

There was a breaking change in it. “NoResource” has been removed. It was not there. The only thing that appeared to be similar to it was “Errors” So quickly without thinking anything else, I patched it and send a pull request.

I was happy, because it was my first contribution for a big project. Then next day when I checked my mail, I was sad. Looked like “NoResource” has been moved to “Twisted.web.Resource” package. I was dumb enough that I failed to see it. My pull request has not been accepted. It was fixed by some one else. Then I remembered something.

”I haven’t failed. I’ve just found 10,000 ways that won’t work.”

Yes, I just found one way in which I cannot submit a pull request.

“If You’ve Never Failed – You Haven’t Tried Hard Enough to Succeed”
“Success does not consist in never making blunders, but in never making the same one a second time.”

I am happy that my pull request got rejected. If a person always agrees to what you say, then you sort of never learn anything. It is only while someone disagrees you, you learn something new.