Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

238
Vistas
Is it possible to use Flask RestX wih Flask's 2.0+ async await?

Usage of async/await was presented in Flask 2.0. (https://flask.palletsprojects.com/en/2.0.x/async-await/)

I am using Flask-RestX so is it possible to use async/await in RestX requests handlers?

Something like:

@api.route('/try-async')
class MyResource(Resource):
    @api.expect(some_schema)
    async def get(self):
        result = await async_function()
        return result

is not working and when I try to reach this endpoint I'm getting error:

TypeError: Object of type coroutine is not JSON serializable

Is there any info on that?

Package versions:

flask==2.0.1
flask-restx==0.4.0

and I've also installed flask[async] as documentation suggests.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

I've gotten around this by using an internal redirect

@api.route('/try-async')
class MyResource(Resource):
    @api.expect(some_schema)
    def get(self):
        return redirect(url_for('.hidden_async'), code=307)

@api.route('/hidden-async', methods=['GET'])
async def hidden_async():
    result = await async_function()
    return result

Redirecting with code=307 will ensure any method and body are unchanged after the redirect (Link). So passing data to the async function is possible as well.

@api.route('/try-async')
class MyResource(Resource):
    @api.expect(some_schema)
    def post(self):
        return redirect(url_for('.hidden_async'), code=307)

@api.route('/hidden-async', methods=['POST'])
async def hidden_async():
    data = request.get_json()
    tasks = [async_function(d) for d in data]
    result = await asyncio.gather(tasks)
    return result
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda