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. 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 and 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 for example. It can be used for some very advanced websocket and realtime features. So Django Channels makes . 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 . 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 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 . 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?