Vitamin C

tornado Getting started with tornado


Tornado is a Python web framework and asynchronous networking library, that uses non-blocking network I/O which allows it to scale to tens of thousands of open connections, making it ideal for long polling, WebSockets, and other applications that require a long-lived connection to each user.


Installation or Setup

Python3 - sudo pip3 install tornado
Python2 - sudo pip install tornado

Packages which will are optional but recommended to install alongside Tornado :

Hello World

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), ])  # URL Mapping

if __name__ == "__main__":
    app = make_app()
    app.listen(8888)    # Port Number

This App is run by typing python3 or python depending on the version of Python being used.
When run locally the server can be accessed by going to from the browser.
The server will return "Hello World".
In make_app() function, the root / is mapped to MainHandler. This means that requests to the root IP will be mapped to the MainHandler function.

Got any tornado Question?