[Python] How to await within a Firebase Cloud Function in Python [duplicate]

Discussão em 'Python' iniciado por Stack, Março 24, 2025.

  1. Stack

    Stack Membro Participativo

    Can Firebase functions be marked as async?

    For example:

    async def async_function() -> str:
    print("async function starting")
    await asyncio.sleep(1)
    print ("async function finished")
    return "finished"

    @https_fn.on_request()
    async def sample_cloud_function(req: https_fn.Request) -> https_fn.Response:
    result = await async_function()
    return https_fn.Response(result)


    The above throws a type error when emulating:


    TypeError: The view function did not return a valid response. The return type must be a string, dict, list, tuple with headers or status, Response instance, or WSGI callable, but it was a coroutine.
    ​

    But I am able to deploy it. When deploying though nothing happens, I get a warning saying the function is never awaited.

    I also can't find documentation on this. What are best practices here?

    Continue reading...

Compartilhe esta Página