DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • MLOps: Definition, Importance, and Implementation
  • You’ve Got Mail… and It’s a SPAM!
  • What Is JHipster?
  • Testing Applications With JPA Buddy and Testcontainers
  1. DZone
  2. Coding
  3. Frameworks
  4. Tornado vs. FastAPI: Why We Made the Switch

Tornado vs. FastAPI: Why We Made the Switch

This article will discuss the key differences between Tornado and FastAPI, two popular web frameworks for Python.

Andrei Tetka user avatar by
Andrei Tetka
·
Apr. 19, 23 · Opinion
Like (2)
Save
Tweet
Share
3.54K Views

Join the DZone community and get the full member experience.

Join For Free

As developers, we are always on the lookout for tools and technologies that can improve our products and services. In this article, we will discuss the key differences between Tornado and FastAPI, two popular web frameworks for Python. Additionally, we will explain why we at Rеblаzе decided to switch from Tornado to FastAPI to enhance our offerings.

Background: Tornado and FastAPI

Tornado is an asynchronous networking library and web framework designed for handling long-lived connections and providing real-time updates in web applications. It has been around since 2009 and is well-established in the Python ecosystem.

FastAPI, on the other hand, is a relatively newer web framework, first released in 2018. It is built on top of the Starlette framework and the Pydantic library, providing a high-performance and easy-to-use solution for developing APIs. FastAPI has gained significant traction in recent years and is known for its speed, simplicity, and versatility.

Key Differences Between Tornado and FastAPI

Performance

FastAPI is known for its outstanding performance, thanks to its asynchronous nature and the underlying ASGI (Asynchronous Server Gateway Interface) server. It offers better concurrency and can handle a larger number of simultaneous connections compared to Tornado, which is built on the WSGI (Web Server Gateway Interface) standard.

We made a performance test but will be better if I add a link to a full comparison of different Python's rest frameworks.

Type Annotations and Validation

FastAPI takes full advantage of Python's type annotations and the Pydantic library to automatically validate request and response data. This feature helps reduce the amount of boilerplate code and potential errors in data validation. Tornado, however, lacks built-in support for type annotations and requires additional libraries or manual validation.

Automatic Documentation

FastAPI аutomatically generates interactive API documentation using OpenAPI and JSON Schema standards. This feature simplifies the process of testing and debugging APIs and ensures accurate documentation. Tornado does not have built-in support for automatic API documentation, and developers must rely on third-party tools or manually maintain API documentation.

Dependency Injection

FastAPI has a built-in dependency injection system that simplifies managing dependencies, reduces boilerplate code, and enforces a clear separation of concerns. Tornado does not provide a built-in dependency injection mechanism, requiring manual dependency management or the use of external libraries.

Learning Curve and Community

FastAPI boasts comprehensive and well-structured documentation, making it easier for developers to learn and adopt. Additionally, the FastAPI community has been growing rapidly, providing a wealth of resources and support. While Tornado has a mature community, its documentation and learning resources may not be as extensive or beginner-friendly as FastAPI's.

Example: Creating a simple "Hello, World!" API endpoint

Tornado:

Python
 
import tornado.ioloop
import tornado.web

class HelloWorldHandler(tornado.web.RequestHandler):
    def get(self):
        self.write("Hello, World!")

def make_app():
    return tornado.web.Application([
        (r"/", HelloWorldHandler),
    ])

if __name__ == "__main__":
    app = make_app()
    app.listen(8080)
    tornado.ioloop.IOLoop.current().start()

FastApi:

Python
 
from fastapi import FastAPI
import uvicorn

app = FastAPI()

@app.get("/")
def hello_world():
    return {"message": "Hello, World!"}

if __name__ == "__main__":
    uvicorn.run(app, host="127.0.0.1", port=8080)


Why We Switched From Tornado to FastAPI

Considering the key differences outlined above, we at Rеblаzе decided to make the switch from Tornado to FastAPI for the following reasons:

Improved Performance: FastAPI's better concurrency and ability to handle more simultaneous connections allow us to serve our customers more efficiently and ensure the best possible user experience.

Simplified Development: The automatic validation, documentation, and dependency injection features of FastAPI streamline our development process, reduce potential errors, and allow us to focus on delivering high-quality features and functionality.

Future-Proofing: FastAPI's growing popularity and active community ensure that we have access to the latest features, updates, and best practices, allowing us to stay ahead of the curve and maintain a competitive edge.

Conclusion

Switching from Tornado to FastAPI has provided Rеblаzе with numerous benefits, including improved performance, simplified development, and better future-proofing. While Tornado remains a powerful and capable web framework, FastAPI's modern features and active community make it an excellent choice.

API Data validation User experience Dependency Framework Python (language)

Opinions expressed by DZone contributors are their own.

Trending

  • MLOps: Definition, Importance, and Implementation
  • You’ve Got Mail… and It’s a SPAM!
  • What Is JHipster?
  • Testing Applications With JPA Buddy and Testcontainers

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: