ConfigsApr 12, 2026·2 min read

Tornado — Python Async Web Framework and Networking Library

Tornado is a Python web framework and asynchronous networking library originally developed at FriendFeed (acquired by Facebook). Non-blocking I/O, WebSockets, long polling, and thousands of simultaneous connections. One of the earliest async Python web frameworks.

TL;DR
Tornado provides non-blocking I/O, WebSockets, and long polling for Python web applications handling thousands of connections.
§01

What it is

Tornado is a Python web framework and asynchronous networking library originally developed at FriendFeed (acquired by Facebook in 2009). It was one of the earliest non-blocking I/O frameworks for Python, designed for applications that need to maintain thousands of simultaneous connections. Tornado provides its own HTTP server, WebSocket support, long polling, and server-sent events.

Tornado targets Python developers building real-time applications like chat systems, live dashboards, and streaming APIs. While newer frameworks like FastAPI have become more popular for REST APIs, Tornado remains relevant for WebSocket-heavy and long-lived connection workloads.

§02

How it saves time or tokens

Tornado includes an HTTP server, so you do not need a separate WSGI/ASGI server for deployment. Its request handler pattern is straightforward: define a class with get/post methods and register URL patterns. WebSocket support is built in with a simple handler class, eliminating the need for additional libraries.

§03

How to use

  1. Install Tornado: pip install tornado.
  2. Define request handler classes with HTTP method handlers (get, post, etc.).
  3. Create an Application with URL routing and start the IOLoop.
§04

Example

import tornado.ioloop
import tornado.web
import tornado.websocket
import json

class ApiHandler(tornado.web.RequestHandler):
    def get(self):
        self.write(json.dumps({'status': 'ok'}))

class ChatSocket(tornado.websocket.WebSocketHandler):
    connections = set()

    def open(self):
        self.connections.add(self)

    def on_message(self, msg):
        for conn in self.connections:
            conn.write_message(msg)

    def on_close(self):
        self.connections.discard(self)

app = tornado.web.Application([
    (r'/api', ApiHandler),
    (r'/ws', ChatSocket),
])

if __name__ == '__main__':
    app.listen(8888)
    tornado.ioloop.IOLoop.current().start()
§05

Related on TokRepo

§06

Common pitfalls

  • Tornado's callback-based async style predates Python's async/await; newer code should use native coroutines with async def for readability.
  • Tornado runs a single-threaded event loop by default; CPU-bound work blocks all connections. Offload heavy computation to thread pools.
  • Tornado's templating engine is basic compared to Jinja2; most projects integrate Jinja2 for complex HTML rendering.

Frequently Asked Questions

How does Tornado compare to FastAPI?+

FastAPI is newer, uses Python type hints for automatic validation and documentation, and integrates with ASGI servers. Tornado has built-in WebSocket support and its own HTTP server. FastAPI is better for REST APIs; Tornado excels at long-lived connections.

Does Tornado support async/await?+

Yes. Since Python 3.5, Tornado supports native async/await syntax. Modern Tornado code should use async def coroutines instead of the older callback or gen.coroutine patterns.

Can Tornado handle thousands of concurrent connections?+

Yes. Tornado's non-blocking I/O loop handles thousands of simultaneous connections on a single thread. It was designed specifically for this use case at FriendFeed.

Is Tornado still maintained?+

Yes. Tornado continues to receive updates, though the release cadence is slower than newer frameworks. It remains a stable choice for production WebSocket applications.

Does Tornado work with ASGI?+

Tornado has its own HTTP server and event loop, separate from the ASGI ecosystem. You can bridge Tornado and ASGI using adapters, but they are different architectures.

Citations (3)

Discussion

Sign in to join the discussion.
No comments yet. Be the first to share your thoughts.

Related Assets