Inquire now
Back to articles
Feb 11, 2019  | by Maksim Larkin

TOP Fast Python Web Frameworks in 2019

python
TOP Fast 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 develop their projects with it. One of the most popular areas for Python is web development. It would be nice if not only development process could be convenient and fast, but also the projects themselves could impress with speed and stability of work.

Python has many frameworks that save a programmer from routine operations and allow 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 we also identify the fastest of them.

Python Web Frameworks

Django

Django Logo

Version: 2.1.4
Description: The most popular web combine for Python, that solves a lot of problems out of the box (admin, authorization, logging, ORM, etc.). This simplifies the life of a developer, but if we prioritize the speed of work, then sometimes such a combine plays against us and it affects performance. For this reason, it will hardly win the Fastest Python Web Framework nomination in 2019.

Flask

Flask Logo

Version: 1.0.2
Description: The most popular Python framework (It outranks in GitHub rating even Django). It is a popular choice in developing small projects cases that doesn’t need those features that Django does. It allows you to deploy the application quickly. It might faster than Django regarding speed, but it has a very poor feature set out of the box.

AioHTTP

aiohttp logo

Version: 3.5.1
Description: A very attractive asynchronous Python Framework. It has a client and a server version, that significantly hand a blank check when developing. It has very convenient asynchronous requests from the client version, as well as a very good server speed with a large number of requests. It exactly should get into the top three.

Sanic

sanic logo

Version: 18.12
Description: We 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.

Tornado

tornado logo

Version: 5.1.1
Description: Asynchronous veteran of Python movement, that set the trend line to asynchrony in 2010. It is not dated and it got version 5 in 2018. It has a rather high barrier of entry for beginners. It`s popular among old school pythonists, and we think it is for a reason. It should show good results.

Vibora

vibora logo

Tested version: no releases on GitHub
Description: A promising framework that appeared in June 2018 and gained more than 4,000 stars in the last 6 months. It has impressive performance snapshot 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 solid version of the framework, we excluded Vibora.
In GitHub, the developers promise a “fundamentally new” Vibora soon. We’ll see what they can do and we will definitely write about it.

Testing method

The 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/

The 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 was used in the case of asynchronous frameworks.

As an event loop of a library for asynchronous frameworks we decided to use uvloop.

Results

Requests per second

requests per second result

The expected leadership positions of aiohttp and Sanic, but unexpected results from Tornado.

Transfer per second (KB)

Transfer per second (KB) result

In  data rate transferred per second, Django stands behind.

Average Request Time (ms)

average request time (ms) result

Tornado, that we initially relied on, surprises unpleasantly again. Flask impressed, it competes with potential leaders on average request time.

Maximum request time (sec)

maximum request time (sec) result

All the “test objects” showed almost the same results for the maximum query time. Everything was as we expected.

Final Results

12 threads

400 connections

Avg Max Requests/sec Transfer/sec (KB)
Latency (ms) Req/Sec Latency (ms) Req/Sec
Django 147,99 120,91 1,98 640 425,71 78,99
Flask 186,8 65,65 1,75 280 546,2 127,48
aiohttp 165,07 247,16 1,98 585 1966,28 439,72
Sanic 194,8 170,85 1,98 470 1520,9 292,6
Tornado 279,3 101,71 1,74 272 778,75 222,07

Conclusion

Aiohttp: a performance leader in early 2019. If your task requires the ultimate performance – then you should turn your attention to it. In addition, you can experiment with the launch parameters aiohttp, to get most out of it . 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 it was not possible to outrun the leader. In conjunction with the thread on Reddit about security issues – we would not use Sanic right now and would wait for actions from the developers.

Tornado: “disappointment of the year”. Taking the results into the consideration – 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. It has 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.

Flask also showed the expected result. Bypassed Django due to the fact that it has not so rich out of the box functionality. It didn’t reach the speed of asynchronous frameworks. We would choose it in 2019 for the implementation of small pet projects or when speed is important, but there is no desire to deal with asynchronous frameworks .

You can see all benchmark source files in the Python Frameworks Benchmark repository.

If you have questions or suggestions for improving benchmarks – feel free to contact us as contact@startmatter.com or by Issues/PR on a GitHub.

Larkin Maksim, Start Matter 2019

Keep reading