Why Sanic Outperforms Flask, Django, and Tornado in Async Python Web Development
This article compares popular Python web frameworks, presents benchmark results showing that traditional frameworks like Flask, Django, and Tornado lag behind modern async options, and explains why Sanic is the preferred choice for high‑performance, production‑ready asynchronous web applications.
If you think Python web development only involves Flask, Django, or Tornado (and maybe FastAPI), you might be missing the faster async alternatives.
Speed First
Python 3.9.3 supports asyncio and the async/await syntax introduced in 3.5; developers still using only synchronous code are essentially living in the past.
Many async web frameworks based on async/await exist on GitHub. A benchmark project that tests dozens of languages and 226 web frameworks (including Go, Java, PHP) provides data for Python frameworks only.
The results show that classic frameworks like Flask, Django, and Tornado rank near the bottom in raw speed.
Below is the benchmark source code used for the tests:
# Disable all logging features
import logging
logging.disable()
from flask import Flask
from meinheld import patch
patch.patch_all()
app = Flask(__name__)
@app.route("/")
def index():
return ""
@app.route("/user/<int:id>", methods=["GET"])
def user_info(id):
return str(id)
@app.route("/user", methods=["POST"])
def user():
return ""
from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt
def index(request):
return HttpResponse(status=200)
def get_user(request, id):
return HttpResponse(id)
@csrf_exempt
def create_user(request):
return HttpResponse(status=200)
import tornado.httpserver
import tornado.ioloop
import tornado.web
class MainHandler(tornado.web.RequestHandler):
def get(self):
pass
class UserHandler(tornado.web.RequestHandler):
def post(self):
pass
class UserInfoHandler(tornado.web.RequestHandler):
def get(self, id):
self.write(id)
app = tornado.web.Application(
handlers=[
("/", MainHandler),
("/user", UserHandler),
("/user/(\d+)", UserInfoHandler),
]
)
import multiprocessing
from sanic import Sanic
from sanic.response import text
app = Sanic("benchmark")
@app.route("/")
async def index(request):
return text("")
@app.route("/user/<id:int>", methods=["GET"])
async def user_info(request, id):
return text(str(id))
@app.route("/user", methods=["POST"])
async def user(request):
return text("")
if __name__ == "__main__":
workers = multiprocessing.cpu_count()
app.run(host="0.0.0.0", port=3000, workers=workers, debug=False, access_log=False)The benchmark simply returns a response without doing any work, which may not reflect real‑world usage but puts all frameworks on an equal footing.
The winner of this speed race is the async framework Sanic .
Why Use an Async Web Framework?
The biggest enemy in web development is not the user but blocking operations. Async programming eliminates network and file I/O blocking, dramatically improving efficiency; therefore, async is one of the best ways to boost Python performance.
Ecosystem
Some may wonder why we recommend Sanic over Falcon, which can be faster in raw benchmarks. Below is a simple Falcon example:
from wsgiref.simple_server import make_server
import falcon
class ThingsResource:
def on_get(self, req, resp):
"""Handles GET requests"""
resp.status = falcon.HTTP_200 # This is the default status
resp.content_type = falcon.MEDIA_TEXT # Default is JSON, so override
resp.text = ("
Two things awe me most, the starry sky "
"above me and the moral law within me.
"
"
"
" ~ Immanuel Kant
")
app = falcon.App()
things = ThingsResource()
app.add_route('/things', things)
if __name__ == '__main__':
with make_server('', 8000, app) as httpd:
print('Serving on port 8000...')
httpd.serve_forever()While Falcon can be fast, its ecosystem is limited; developers need many features out of the box, which is why most Python web developers still prefer Django, Flask, or Tornado.
Since its first release in May 2016, Sanic has matured over five years into a stable, high‑performance framework.
The awesome-sanic project lists numerous third‑party extensions covering API, authentication, monitoring, ORM, caching, queues, and more—essentially anything you can imagine.
Production Use
Since late 2019, the author has been running Sanic in production (versions 19.9 through 21.3), confirming its readiness for real‑world deployments.
Sanic was designed from the start to be production‑grade; unlike some frameworks that warn against using the built‑in run method for deployment, Sanic’s run command can be used directly, eliminating the need for external servers like Gunicorn.
Documentation
Many Python developers start with Flask or Django, but Django’s newer features often lack Chinese documentation, creating a barrier for non‑English speakers. Sanic, however, provides comprehensive Chinese guides and API docs, officially maintained and continuously expanded to include Korean, Portuguese, and other languages.
Community Support
Sanic’s community channels—official forums, Discord, GitHub issues, Twitter, and Stack Overflow—are all operated by the core team, allowing direct interaction with maintainers and a clean, ad‑free environment.
What are you waiting for? Try Sanic today and remember its vision: Build Faster, Run Faster!
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
