Which Python Web Framework should I learn in 2021?

Tram Ho

Web Framework is generally divided into 2 categories: full-feature framework and micro framework. In Python, the typical full-feature framework is Django, and the micro framework is Flask.

The full-feature framework and the micro framework simply differ in the number of features bundled within the framework.

The full-feature framework will cover everything from routing, template engine, session, persistence, authentication & authorization … to more advanced features like caching, scheduler, worker …

Conventional micro frameworks have only routing and filter / middleware attached. Other components that you want to use are manually added via extension / plugin / module …

If classified by server, the Python Web Framework has two groups. One group uses WSGI, the other group uses ASGI. WSGI was born before, using traditional blocking I / O mechanism such as Apache Httpd, Java Servlet … ASGI has later, using non-blocking I / O mechanism similar to Nginx, Nodejs, Vertx .. .

WSGI has supporting frameworks: Django, Flask, Pyramid, TurboGears …

ASGI has supporting frameworks: FastAPI, Falcon, Sanic, Hug …

There are currently a number of frameworks that allow you to choose between WSGI and ASGI when bootstrap new projects. Depending on your preferences and requirements, you should consider choosing a suitable server.

Going back to the original question, which Python Web Framework should I learn in 2021? In short: full-feature is Django, micro is FastAPI. It is simply that these two guys are the best today, strong community, modern features.

Django is amazing, and has been tested for decades. Doing web, doing REST API is fine. Write model, write a bit of routing and then generate the code to generate an admin dashboard, which is very suitable for things to do MVP quickly. Of course, if you want to customize deeply, it’s also complicated, not as simple as the introduction!

FastAPI – this guy is a newbie, only about 2–3 years ago but growing very fast. This nature is also based on existing projects like Starlette, Pydantic, Swagger … but repackaged, added some high-level APIs for ease of use. FastAPI is great for REST API and microservices because it’s lightweight and relatively easy to customize. Meete has been in production for almost 2 years and has evaluated resource usage and performance very well.

Also, the author of FastAPI is very nice, there is a problem you can respond to him directly on Twitter.

Ok! Now let’s study!


Share the news now

Source : Viblo