paint-brush
Django too big, Flask too small, Tornado just right!by@pizzapanther
16,176 reads
16,176 reads

Django too big, Flask too small, Tornado just right!

by Paul BaileySeptember 19th, 2017
Read on Terminal Reader
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

Quite often in the Python web world when asked to build a web application you choose between the two most popular Python web ecosystems, Django or Flask. However, there are other really capable web frameworks out there that may be better. <a href="http://www.tornadoweb.org/en/stable/" target="_blank">Tornado</a> is one of those frameworks. Tornado is often my secret weapon for specialized projects because of some its unique abilities. It’s definitely smaller than Django but comes prepackaged with a lot of little utilities that will make writing your Python web code a joy. Maybe it’s right for your next project? Here are a few of its abilities that make it stand out in my mind.

Company Mentioned

Mention Thumbnail
featured image - Django too big, Flask too small, Tornado just right!
Paul Bailey HackerNoon profile picture

Quite often in the Python web world when asked to build a web application you choose between the two most popular Python web ecosystems, Django or Flask. However, there are other really capable web frameworks out there that may be better. Tornado is one of those frameworks. Tornado is often my secret weapon for specialized projects because of some its unique abilities. It’s definitely smaller than Django but comes prepackaged with a lot of little utilities that will make writing your Python web code a joy. Maybe it’s right for your next project? Here are a few of its abilities that make it stand out in my mind.

Asynchronous From Before You Were Born

AsyncIO is all the rage these days because of the rise of Node.js and other asynchronous tools. Tornado was built from day one to support async operations. So before Python supported async officially, Tornado was helping you write cleaner async code. It comes with many utilities to assist with it asynchronous operations such as an IOLoop, coroutines, futures, and more. Checkout Tornado’s asynchronous networking and concurrency documentation. All async utilities also work in both Python 2 and 3.

Native Websocket Support

With most web frameworks in Python, websockets are a feature that is added in. This makes their implementations feel a little clumsy or complex at times. Take Django Channels for example. It can be used for some very advanced websocket and realtime features. So Django Channels makes “the hard things possible”. But if you just need a simple websocket, Django Channels is a really complex library to sprinkle in a little realtime capability into your app. With Tornado’s implementation it “keeps the easy things, easy”. This can be very useful in certain situations where you’re not concerned so much about scaling out initially. That’s not to say, that you couldn’t do that, it’s just that Tornado lets you implement websockets very easily and simply. Then you can add on from that. Contrast that with Django Channels which gives you more advanced capabilities but also requires a lot more setup and code to get started.

Third-party Login Support

Tornado comes with support for social logins right out of the box. I find this really convenient because for smaller web apps, if I need a login system, I like to use third-party logins. This lets me outsource a big chunk of my app that I really don’t want to worry about.

CLI Options and Config File Parsing

A lot of times when I need to write web services, I would like to include some command line options or have the option to parse a config file or both. Tornado also includes built in options/config file utilities. Again this just really makes it convenient to write web services and package in configuration options that make it operate like other common command line tools.

The Other Stuff

Tornado also comes with other things you’d expect to see in a web framework like templating, routing, cookie utilities, request parsing, etc. I’ve also found that while it’s not the most popular framework, it still has a good ecosystem of people supporting it and building libraries that work with it. So check it out for your next project. Maybe it will be the perfect fit?