Learn TORNADO-REST with Real Code Examples
Updated Nov 27, 2025
Explain
Tornado provides an asynchronous, non-blocking web server and framework for Python.
Supports long-lived connections such as WebSockets, making it ideal for real-time apps.
Includes routing, request handlers, and asynchronous HTTP client features.
Handles thousands of concurrent connections with minimal overhead.
Flexible and lightweight, allowing integration with other Python libraries.
Core Features
Asynchronous HTTP server
RequestHandler classes for routing
WebSocketHandler for persistent connections
Integration with Python’s asyncio
Flexible URL routing and parameter handling
Basic Concepts Overview
RequestHandler - class handling HTTP requests
WebSocketHandler - class for WebSocket connections
Application - maps URLs to handlers
IOLoop - core async event loop
Coroutine - async function using async/await
Project Structure
app.py - main application and server entry point
handlers/ - HTTP and WebSocket handlers
services/ - optional business logic
static/ - optional static files
requirements.txt - dependencies
Building Workflow
Define request handlers for API endpoints
Set up URL routing in Application
Implement async methods using coroutines
Integrate WebSocketHandlers if needed
Run the server on IOLoop and test endpoints
Difficulty Use Cases
Beginner: basic hello-world endpoint
Intermediate: CRUD REST API with async handlers
Advanced: WebSocket chat server
Expert: high-concurrency real-time microservices
Enterprise: IoT or streaming APIs with async processing
Comparisons
Tornado vs Flask: Tornado async and high-concurrency, Flask synchronous and simple
Tornado vs FastAPI: FastAPI more structured, Tornado lower-level async
Tornado vs Django REST Framework: DRF more feature-rich, Tornado lightweight and async
Tornado vs Sanic: Both async; Sanic higher-level API helpers
Tornado vs Node.js frameworks: Python ecosystem vs JS event loop
Versioning Timeline
2009 - Initial release by FriendFeed engineers
2010 - Tornado 1.x stable with HTTP server
2013 - Tornado 3.x async enhancements
2017 - Tornado 5.x Python 3-only support
2025 - Latest Tornado 6.x with modern async/await support
Glossary
RequestHandler - class handling HTTP requests
WebSocketHandler - class for WebSocket connections
Application - maps URLs to handlers
IOLoop - async event loop for non-blocking operations
Coroutine - async function using async/await