Is FastAPI going to replace Django (Comparison of Github Stars and Stack Overflow Survey)
If you are a backend developer then there is only a slim chance that you haven’t heard of Django, it is typically the framework of choice for Python backend development. But as Django more and more features got added to the Django Core Framework we start to encounter new problems with the way that Django is implemented.
What is FastAPI?
FastAPI is a modern, fast (high-performance), web framework for building APIs with Python 3.6+ based on standard Python type hints.
For me the key features are:
- Fast: Very high performance, on par with NodeJS and Go (thanks to Starlette and Pydantic). One of the fastest Python frameworks available.
- Fast to code: Increase the speed to develop features by about 200% to 300%. Take a look https://fastapi.tiangolo.com/tutorial/first-steps/. It takes only 4 lines of code to create a view which also has an REST Interface.
- Short: Minimize code duplication. Multiple features from each parameter declaration. Fewer bugs.
- Robust: Get production-ready code. With automatic interactive documentation.
Problems with Django
Django is a fantastic framework, but its fundamental issue is that it became a huge project. As a result, adding new features or altering existing ones requires a lot of work.
The fact that Django currently lacks native support for RestAPIs and requires the installation of the Django REST framework package serves as an illustration of this. Jinja is currently available right out of the box. This is primarily because Django is an ancient project that was started when APIs weren’t as well-known as they are now. But to be honest, I really dislike Jinja, it is just such a messy technology to create frontend. Therefore, I use React for my frontend.
Comparison of Github Stars (total amount and grow)
In my last article “Python Web development in 2022: Which web frameworks are the most popular by Github stars?” I analysed the Github Stars for both frameworks. Django is still on first place with 65,687 stars and FastAPI is on the third place with 44,121. Beside that fact, FastAPI was growing by 38% from 2021 to 2022. When will FastAPI overtake Django?
As we can see in the above table, it will still take 3 years for FastAPI to overtake Django (assumption: the annual growth of Django is 18.84% and of FastAPI is 38.09%)
Stack Overflow Survey 2021 and 2022
In 2021 and 2022 Django was the 9th place of the most used web frameworks. FastAPI was on the 15th place in 2021 and 14th place in 2022.
The growth of FastAPI from 2021 to 2022 was over +55%. In the meantime, Django declined by 2.27%
Personal Conclusion
Django is still the best Python Framework for medium and large projects, but I think FastAPI will be the best option if you just want to create a RestAPI.
I’m curious to know what you think of Django and the FastAPI. Comment below.