📜 ⬆️ ⬇️

Little Python Joy # 2: Starlette


Tunnel vision


It so happened that many web applications are written in Python. Python development niche is almost completely divided between two healthy players - Django and Flask. Therefore, a large percentage of Python programmers are sharpened to work with these two frameworks.


For this reason, many Python developers develop some semblance of tunnel vision — their engineering approach is locked between these two libraries.


Some programmers are not limited to Djano and Flask and add all sorts of new things to their combat tools. For example, the fashionable framework Sanic .


Tectonic shift: from WSGI to ASGI


In a period of hectic adaptation of Python to the needs of web development, the community came up with the WSGI standard - the Web Server Gateway Interface. This protocol described how a web server could send HTTP requests to processing applications in Python and receive responses from there.


WSGI has opened the way for the development of many frameworks and libraries for web development. All of them were different in their architecture, but the same in their way of communicating with an external web server. WSGI was introduced by the community in 2003, and all the popular classic python web frameworks (including Django and Flask) still support it.


The problems with WSGI began after powerful tools appeared in the Python core for asynchronous code execution and cortina. WSGI is old and in no way sharpened to work with new language features. Therefore, there is a need for a new, asynchronous protocol of communication between the web server and Python programs. This is how ASGI (Asynchronous Server Gateway Interface) appeared - an ideological descendant of WSGI , but with cortutins and asychron.


The developers of the old frameworks were taken hostage by their audience - they just cannot take and transfer their frameworks to an asynchronous approach (this will break the code and destroy compatibility), so all the development using ASGI has been concentrated in new frameworks released in the last couple of years and Django .


Starlette - a brilliant framework



Starlette is a new, smart and cool framework implementing the ASGI approach. In it, everything is sharpened on asynchrony and new chips of the 3rd branch of Python.


In addition, Starlette has a whole bunch of serious buns.



Solid lotion - FastAPI



Some Starlette programmers liked it wildly and they created an extension for this framework - FastAPI


FastAPI is, in fact, a patch to Starlette's native classes, adding a pack of new features to an already good framework.



And a number of small beautiful and convenient.


The bottom line


It's time to dive into the world of ASGI and its frameworks (if, of course, you have not done so yet). Asynchronous solutions are far from dominating the market, but they are actively coming. And first of all - because of its speed.


')

Source: https://habr.com/ru/post/454440/


All Articles