Open In App

Introduction to Tornado Framework

Last Updated : 26 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Tornado is a robust Python asynchronous networking library and web framework, is available as an open-source project. Given that it is made to manage non-blocking, asynchronous processes, it is appropriate for developing high-performance, scalable web apps. Since its creation, Tornado—which was first created by FriendFeed—has been well-known for its ease of use, quickness, and ability to handle stable network connections.

Prerequisites

Key features of Tornado:

  • Asynchronous I/O: Tornado is well-suited for applications requiring high concurrency since it is designed to manage thousands of simultaneous connections in an efficient manner.
  • WebSockets: Tornado supports WebSockets, which allows clients and servers to communicate in real time.
  • Request Handlers: To handle incoming HTTP requests, Tornado employs the request-handler pattern. Classes called handlers specify how to reply to various kinds of requests.
  • Built-in Authentication and Authorization: Tornado comes with built-in ways to manage user authentication and authorization, which simplify the process of securing your apps.
  • Scalability: Tornado is well-suited for developing scalable web applications due to its capacity to manage several connections at once.

Lets create a basic tonado project:

Step 1 : Make sure Python is set up on the machine or From the Python website, we can get the most recent version. To check python installed or not run this command

>> python --version

Step 2 : Now, we have to install tornado framework, by using this command

>> pip install tornado

Step 3 : After the installation now we have to create a app.py and write some basic code in it.

Python




import tornado.ioloop
import tornado.web
 
class HomeHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, Tornado Home!")
 
class AnotherHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, Tornado Another!")
 
def make_app():
    return tornado.web.Application([
        (r"/", HomeHandler),
        (r"/another", AnotherHandler),
    ])
 
if __name__ == "__main__":
    app = make_app()
    app.listen(8888)
    print("running in http://localhost:8888/")
    tornado.ioloop.IOLoop.current().start()


Step 4 : Now the project has been created. now the project is ready to serve. To run the development server follow this command.

>> python app.py

The project runs successfully to see that open the serving URL(http://localhost:8888/) and open it on the browser.

In this project, the HomeHandler responds with “Hello, Tornado Home!” when the root URL (“/”) is accessed.

Animation2

output

The output shown in the browser upon launching the Tornado program is seen in this screenshot.

Conclusion

In conclusion, By exploring Tornado Framework is uncovered the robust and versatile toolsets for web application. Whether you’re building a small-scale application or a complex, real-time system, Tornado’s capabilities and performance optimizations make it a framework worth exploring and integrating into your development toolkit.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads