Python Web Server with Tornado

Tornado is an Open Source Web Server for Python really interesting. It powers the FriendFeed and it is listed in the Facebook Open Source Technology page for Infrastructure.

I tried quickly on my Ubuntu 10.10 Laptop and it is really simple to install and test.

Just open a terminal and type:

  • sudo apt-get install python-pycurl
  • sudo apt-get install pip
  • sudo pip install tornado
  • vi hello.py and write an hello world web application like this
  • import tornado.ioloop
    import tornado.web
    
    class MainHandler(tornado.web.RequestHandler):
      def get(self):
      self.write("Hello, world")
    
      application = tornado.web.Application([
        (r"/", MainHandler),
      ])
    
    if __name__ == "__main__":
      application.listen(8888)
    
  • python hello.py
  • open the browser and go to http://localhost:8888

Thats it!

3 thoughts on “Python Web Server with Tornado

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s