Skip to content
Advertisement

How to use async await in python falcon?

I am looking for example of using async await features of python 3. I am using falcon framework for building rest api. Can’t figure out how to use async await with it.

Please help me, by providing some examples, maybe with other frameworks.

Thank you!

Advertisement

Answer

Update: as of Falcon 3.0, the framework supports async / await via the ASGI protocol.

In order to write async Falcon code, you need to use the ASGI flavour of App, for instance:

JavaScript

Assuming the above snippet is saved as test.py, the ASGI application can be run as

JavaScript

Setting and retrieving the message with HTTPie:

JavaScript
JavaScript

Note that when using the ASGI flavour of Falcon, all responders, hooks, middleware methods, error handlers etc must be awaitable coroutine functions, as the framework does not perform any implicit wrapping or scheduling in an executor.

See also Falcon’s ASGI tutorial.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement