Node.js has changed the JS world forever, So as a python developer at that time I thought hey why can’t we bring that architecture to python (we already had generators ), even though it was a bit late the asyncio feature was released on the 3.4 version.

So what does it do, compare to JS async/await statement

Let us see an example of how asyncio works in python

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
import asyncio

async def saySomething():
    print("Hai")
    await asyncio.sleep(1)
    print("Ok Bye")

async def main():
    await asyncio.gather(saySomething(), saySomething(), saySomething())

if __name__ == "__main__":
 
     asyncio.run(main())      

ok, so what happens when we run the program

1
2
3
4
5
6
7
8
9
 **Output**
 ----------------------------------------------------------------
 
 Hai
 Hai
 Hai
 Ok Bye
 Ok Bye
 Ok Bye

Now we are seeing something that we have only seen in a browser console. This is now officially supported in python 😌

So the heading was about Quart?

Let’s get down with what Quart is, to be frank, its an exact fork of Flask the minimal web framework for python, for the past few months I have been working on a project to do some System-Level I/O stuff,

It has proved its worth on an Event-Driven system ,the benchmark was so promising and the performance is notable.

3X faster than flask to be exact with minimal response time’s (Tested with PostgreSQL)

RouteRequest per second FlaskRequest per second QuartLatency FlaskLatency Quart
GET /films/995/330.221160.2760.5517.23
GET /films/99.39194.58201.14102.76
POST /reviews/324.491113.8161.6018.22

The only thing to keep in mind is that it can’t do heavy computation similar to JS. But could make a hell of an HTTP server and has build-in support for

  • HTTP/1.1 requests streaming.

  • Websockets.

  • HTTP/2 server push.

  • HTTP/3 (I think it’s already in work)

If you plan to migrate your old flask codebase to Quart it’s easy as pie, See the Code for yourself.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
    import asyncio
    
    from quart import Quart
    
    from routes.disk_api import disks_api
    
    
    app = Quart(__name__)
    
    
    #routes for disk api
    
    app.register_blueprint(disks_api, url_prefix='/api/disks')
    
    
    if __name__ == '__main__':
         app.run(host = '0.0.0.0',port=5000)

So guys why not give it a trie, plus don’t try to block the event loop 😝

Visit https://gitlab.com/pgjones/quart for more info