Frameworks

Broadly speaking, a web framework consists of a set of libraries and a mainhandler within which you can build custom code to implement a web application(i.e. an interactive web site). Most web frameworks include patterns andutilities to accomplish at least the following:

URL Routing
Matches an incoming HTTP request to a particular piece of Python code tobe invoked
Request and Response Objects
Encapsulates the information received from or sent to a user’s browser
Template Engine
Allows for separating Python code implementing an application’s logic fromthe HTML (or other) output that it produces
Development Web Server
Runs an HTTP server on development machines to enable rapid development;often automatically reloads server-side code when files are updated

Django

Django is a “batteries included” webapplication framework, and is an excellent choice for creating content-orientedwebsites. By providing many utilities and patterns out of the box, Django aimsto make it possible to build complex, database-backed web applications quickly,while encouraging best practices in code written using it.

Django has a large and active community, and many pre-built re-usablemodules that can be incorporated into a newproject as-is, or customized to fit your needs.

There are annual Django conferences in the United States, Europe, and Australia.

The majority of new Python web applications today are built with Django.

Flask

Flask is a “microframework” for Python, and isan excellent choice for building smaller applications, APIs, and web services.

Building an app with Flask is a lot like writing standard Python modules,except some functions have routes attached to them. It’s really beautiful.

Rather than aiming to provide everything you could possibly need, Flaskimplements the most commonly-used core components of a web applicationframework, like URL routing, request and response objects, and templates.

If you use Flask, it is up to you to choose other components for yourapplication, if any. For example, database access or form generation andvalidation are not built-in functions of Flask.

This is great, because many web applications don’t need those features.For those that do, there are manyExtensions available that maysuit your needs. Or, you can easily use any library you want yourself!

Flask is default choice for any Python web application that isn’t a goodfit for Django.

Falcon

Falcon is a good choice when your goal isto build RESTful API microservices that are fast and scalable.

It is a reliable, high-performance Python web framework for building large-scaleapp backends and microservices. Falcon encourages the REST architectural style ofmapping URIs to resources, trying to do as little as possible while remaining highly effective.

Falcon highlights four main focuses: speed, reliability, flexibility, and debuggability.It implements HTTP through “responders” such as on_get(), on_put(), etc.These responders receive intuitive request and response objects.

Tornado

Tornado is an asynchronous web frameworkfor Python that has its own event loop. This allows it to natively supportWebSockets, for example. Well-written Tornado applications are known tohave excellent performance characteristics.

I do not recommend using Tornado unless you think you need it.

Pyramid

Pyramid is a very flexible framework with a heavyfocus on modularity. It comes with a small number of libraries (“batteries”)built-in, and encourages users to extend its base functionality. A set ofprovided cookiecutter templates helps making new project decisions for users.It powers one of the most important parts of python infrastucturePyPI.

Pyramid does not have a large user base, unlike Django and Flask. It’s acapable framework, but not a very popular choice for new Python webapplications today.

Masonite

Masonite is a modern and developer centric, “batteries included”, web framework.

The Masonite framework follows the MVC (Model-View-Controller) architecture pattern and is heavily inspired by frameworks such as Rails and Laravel, so if you are coming to Python from a Ruby or PHP background then you will feel right at home!

Masonite comes with a lot of functionality out of the box including a powerful IOC container with auto resolving dependency injection, craft command line tools, and the Orator active record style ORM.

Masonite is perfect for beginners or experienced developers alike and works hard to be fast and easy from install through to deployment. Try it once and you’ll fall in love.

FastAPI

FastAPI is a modern web framework for buildingAPIs with Python 3.6+.

It has very high performance as it is based on Starletteand Pydantic.

FastAPI takes advantage of standard Python type declarations in function parametersto declare request parameters and bodies, perform data conversion (serialization,parsing), data valdiation, and automatic API documentation with OpenAPI 3(including JSON Schema).

It includes tools and utilities for security and authentication (including OAuth2 with JWTtokens), a dependency injection system, automatic generation of interactive APIdocumentation, and other features.