Fastest Python web frameworks in 2019
In 2018, Python strengthened its popularity among programmers and entered the Top 3 most popular languages on github . More and more people are going to the bright side ... that is, Python. There is an even greater number of developers who are interested in this language and are developing their projects with it. One of the popular areas for Python is web development. It would be desirable that not only the development process was convenient and fast, but also the projects themselves could boast of speed and stability of work.
Python has many frameworks that save the programmer from the routine operations and allow you to focus on solving problems. In 2018, the existing frameworks were updated and new tools appeared.
Therefore, we decided to make a comparative analysis of popular frameworks that will not lose, we hope, their relevance throughout 2019 and determine the fastest of them.
Description: the most popular combine for Python, which out of the box solves many problems (admin, authorization, logging, ORM, etc.). This simplifies the life of the developer, but if we prioritize the speed of work, then sometimes such a combine plays against us and this affects performance. For this reason, he most likely will not take the Fastest Python Web Framework in 2019 nomination.
Description: The most popular Python framework (by stars in GitHub even overtakes Django). A popular choice in cases of developing small projects that do not need those buns that are in Django. Allows you to quickly deploy the application. Perhaps faster than Django for speed, but has very little out-of-box functionality.
Description: A very attractive asynchronous Python Framework. It has a client and server version, which significantly frees the hands when developing. It has very convenient asynchronous requests from the client version, as well as very good server speeds with a large number of requests. Exactly should get into the top three.
Description: You can say that this is a “multi-threaded Flask” with all the consequences. For this reason, we think that the results should be very good.
Description: Asynchronous veteran of Python movement, which set the asynchronous trend in 2010. Does not lose its relevance and received version 5 in 2018. Enough high entry threshold for beginners. Popular among old school pythonists, and we think for good reason. Must show good results.
Testing version: no releases on GitHub
Description: a promising framework that appeared in June 2018 and in the last six months gained more than 4,000 stars. It has impressive performance measurements on GitHub. We thought that Vibora would be the favorite of our race, but unfortunately, due to the lack of the ability to run under Python> = 3.7 and the lack of a stable version of the framework, we excluded Vibora.
In GitHub, the developers promise a “cardinally new” Vibora soon. We'll see what they can do and be sure to write about it.
Testing was performed on Apple iMac 27 '' Retina 5K 2017, CPU: 3.5GHz i5, RAM: 8GB, 1000GB Fusion Drive, OSX 10.14.2 using the WRK utility :
wrk -t12 -c400 -d30s http://127.0.0.1:8080/db/
Tests were conducted in Python 3.7.2. All frameworks were launched using Gunicorn with two workers. Perhaps in some cases, the use of uwsgi would have affected the results, but since we set the goal to test frameworks, rather than how to launch them, we decided to ignore this.
We had only one type of test: DB Test, in which we get the string data from the database and return it as an html-response (1 record in 79 bytes). Postgres 11 was used as a database. Psycopg2 was used as a driver for database access in the case of synchronous frameworks and asyncpg in the case of asynchronous frameworks .
As an event loop library for asynchronous frameworks decided to use uvloop.
Requests per second
The expected leadership positions of aiohttp and Sanic, but unexpected results from Tornado.
Data transfer per second (kb)
By the number of transmitted data per second Django lags far behind.
Average request time (ms)
Again it is unpleasantly surprising Tornado, on which we initially relied. Impresses with Flask, which on average request time competes with potential leaders.
Maximum request time (sec)
All the "experimental" showed almost the same results for the maximum query time. All as we expected.
|Avg||Max||Requests / sec||Transfer / sec (KB)|
|Latency (ms)||Req / Sec||Latency (ms)||Req / Sec|
Aiohttp: performance leader in early 2019. If your task requires the ultimate performance - then you should look at it. In addition, you can experiment with the launch parameters aiohttp, to squeeze out of it even more. It has a client version that allows you to make asynchronous requests without additional libraries. Therefore, to implement our new high-load service, we chose it.
Sanic: the popularity of the framework goes ahead of its performance. The miracle did not happen and overtake the leader did not work. In conjunction with the thread on Reddit about security issues - we would not use Sanic right now and wait for action from the developers.
Tornado:“Disappointment of the year”. In connection with the results - we do not think that Tornado should be chosen to implement any new projects. We hope the developers will come up with something and fix the situation.
Django showed the expected result. We love Django for its capabilities and freeing us from the routine, and not for the speed of work. Extensive community, a large number of materials on the web, a large number of completed projects in the public domain - all this makes it attractive for beginners. If we had the task to quickly develop the MVP of a typical web service, we would choose it in 2019.
Flaskalso showed the expected result. Bypassed Django due to the fact that it has not so rich functionality out of the box. Not reached the speed of asynchronous frameworks. We would choose it in 2019 for the implementation of small pet projects or when speed is already important, but there is no desire to deal with asynchronous frameworks yet.
All source files of benchmarks you can see in the Python repository Frameworks Benchmark .