Tornado is a web framework and asynchronous networking library, originally developed at FriendFeed. It enables real-time web applications to scale up to tens of thousands of open connections, making it ideal for long-lived network connections such as chat protocols.
Features
- Asynchronous I/O: Tornado is built around an asynchronous I/O loop, allowing you to handle many connections at once using a single thread.
- Web Server: Tornado comes with a built-in HTTP server, which is useful for development and for serving static files.
- WebSockets: Tornado supports WebSockets, which allows for full-duplex communication between the server and the client.
Getting Started
Before you start, make sure you have Python installed on your system. Tornado requires Python 3.5 or newer.
Installation
You can install Tornado using pip
:
pip install tornado
Basic Example
Here's a simple Tornado web server that serves a single page:
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.write("Hello, world")
def make_app():
return tornado.web.Application([
(r"/", MainHandler),
])
if __name__ == "__main__":
app = make_app()
app.listen(8888)
tornado.ioloop.IOLoop.current().start()
Run the script, and open your web browser to http://localhost:8888
. You should see "Hello, world".
Further Reading
For more information, you can check out the official Tornado documentation.
Tornado Logo