GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — FR: Async requests · Issue #104 · firebase/firebase-admin-python

FR: Async requests #104

New issue
Copy link
New issue
Copy link
Open
Open
FR: Async requests#104
Copy link
Assignees
lahirumaramba
Labels
api: core

Description

@eranhirs
eranhirs
opened on Dec 11, 2017
Issue body actions

I am using firebase-admin on an asyncio project and when there are a lot of requests it slows down the whole API.

Surprisingly, I didn't see any other issues about this, I hope I am not duplicating.

ref = yield from db.reference
result = yield from ref.get()

Thanks

Reacted by Ashwin Raghav, Iman Mirzadeh, Chanhyeong Lee, Etienne Landuré, Simon, Tarek Salama, KHELIFI Ahmed Aziz, Tuukka Mustonen, Tuukka Mustonen, Lenormand Julien and 1 more

Activity

Next
  1. hiranya911 commented on Dec 11, 2017

    @hiranya911
    hiranya911
    on Dec 11, 2017
    Contributor
    More actions

    Can this be not handled in the application code? Basically execute Admin SDK methods like ref.get() on separate threads.

    Reacted by Jon Goodrum
    Reacted by Rémy HUBSCHER, Victor Malov, Samuel Stroschein, Clament John, Spinne, Iman Mirzadeh, icnahom, ChenCheng Jiang, Artem Belyakov, denisolyanyuk and 1 more
  2. eranhirs commented on Dec 12, 2017

    @eranhirs
    eranhirs
    on Dec 12, 2017
    Author
    More actions

    It won't scale as I would like and, to my opinion, complicates the code and is harder to track.

  3. hiranya911 commented on Dec 12, 2017

    @hiranya911
    hiranya911
    on Dec 12, 2017
    Contributor
    More actions

    Most of our users are on Python 2.7, so we cannot directly expose async coroutines from the SDK anytime soon. In the meantime you should be able to get around the scalability issues by using the run_in_executor() method of the asyncio event loop.

    ref = db.reference(path) # Doesn't make RPC calls
    
    executor = concurrent.futures.ThreadPoolExecutor(max_workers=8)
    loop = asyncio.get_event_loop()
    loop.run_in_executor(executor, ref.get) # Make RPC call on a separate thread
    
    Reacted by Jon Goodrum and Ashwin Raghav
  4. hiranya911
    closed this as completedon Dec 12, 2017
  5. eranhirs commented on Dec 13, 2017

    @eranhirs
    eranhirs
    on Dec 13, 2017
    Author
    More actions

    In case anyone runs into the same problem -
    Eventually, I am using the REST API.
    Calling it asynchronously with aiohttp.

    For auth I am using the database secret which is DEPRECATED, so it's not ideal, but it works for now.

    Reacted by Rémy HUBSCHER, Victor Malov, Daniel and Dominik Magdaleński
    Reacted by Daniel
  6. Natim commented on Mar 5, 2019

    @Natim
    Natim
    on Mar 5, 2019
    More actions

    @eranhirs would you feel like starting a async-firebase project that we could contribute to?

  7. hyperknot commented on Apr 17, 2019

    @hyperknot
    hyperknot
    on Apr 17, 2019
    More actions

    I wanted to report that having async support for an auth SDK is very important. This is exactly the area where async frameworks make a huge difference, where you do a client side request inside a server side request.

    Please consider adding core support and examples for using with ASGI frameworks, like Starlette:
    https://github.com/encode/starlette

    Reacted by Victor Malov, Daniel, Sylvain Hellegouarch, Dev Aggarwal, Philipp Gross, Chanhyeong Lee, Dominik Magdaleński, Takos, cam-matsui, TOLOMIKA and 4 more
  8. Lawouach commented on Jul 26, 2019

    @Lawouach
    Lawouach
    on Jul 26, 2019
    More actions

    I agree with the general feeling here. Not having async support is making this library a tad less useful nowadays. Not very future proof unfortunately.

    Reacted by cam-matsui
  9. labroid commented on Jan 1, 2020

    @labroid
    labroid
    on Jan 1, 2020
    More actions

    +1 on this. My project has a few hundred thousand items that need to be worked via Firebase, and ~1 second latency times make wait times intractable without async support

  10. labroid commented on Jan 1, 2020

    @labroid
    labroid
    on Jan 1, 2020
    More actions

    Python 2.7 is no longer supported. Any progress here?

  11. hiranya911 commented on Jan 1, 2020

    @hiranya911
    hiranya911
    on Jan 1, 2020
    Contributor
    More actions

    This needs to be first addressed in other GCP Python libraries that we use as dependencies. More specifically, the google-auth library (which we use to make all authorized HTTP calls) needs to support it. From what I can see, they have plans to add async support starting from 2020, but there is no concrete timetable as of now:

    googleapis/google-auth-library-python#321
    googleapis/google-cloud-python#3103

    I can only imagine that this will take a while considering the engineering effort that is involved. Pretty much all existing APIs have to be re-evaluated and redesigned for async support.

    If google-auth takes a very long time to introduce async support, we can consider wrapping the existing google-auth APIs in async threads, so that at least firebase-admin can expose an async API to the developer. But even that is going to require a lot of work, based on some prototyping results I've managed to put together.

  12. noahkw
    added a commit that references this issue on Feb 7, 2020

    [DataStore] closes #7

    b46838d
  13. kamyar commented on Jun 3, 2020

    @kamyar
    kamyar
    on Jun 3, 2020
    More actions

    Is there any development on this front?
    Also can you please reopen this issue?
    We have been using firestore and lack of async is a very big downside of firestore.
    If async supported is not planned for google services, It would be nice if we know beforehand so we can plan our migration to services that support it. Lack of this feature is causing us both money and product quality tbh.

  14. hiranya911 commented on Jun 3, 2020

    @hiranya911
    hiranya911
    on Jun 3, 2020
    Contributor
    More actions

    There's been no development in this space afaik. We cannot support an async API until the core GCP Python libraries like google-auth provide async support. For Firestore you can file a feature request directly at https://github.com/googleapis/python-firestore

    Reacted by Kamyar
  15. kamyar commented on Jun 3, 2020

    @kamyar
    kamyar
    on Jun 3, 2020
    More actions

    It seems there is an open PR related to adding async support.

    One of the contributors to the libraries just left a comment.

    Would be great to hear about firebase-admin maintainers/contributors perspective on this. :)

    Edit: I will look into the repo you linked and file a feature request maybe, thanks for the reply :)

  16. 5 remaining items

  17. lahirumaramba commented on Apr 9, 2021

    @lahirumaramba
    lahirumaramba
    on Apr 9, 2021
    Member
    More actions

    Good news! We are prioritizing this task and have plans to start the initial planning work over the coming months. It is still too early to provide a timeline, but I will reopen this issue so we can track the progress here. Thank you everyone for your patience!

    Reacted by Dominik Magdaleński, Alexander, Chanhyeong Lee, Leo Trubach, Amit Krishna A, Etienne Landuré, David Nellessen and icnahom
    Reacted by Brad Reardon, Samuel Stroschein, Notmeor, Kamyar, Anand, Fernando Alves, Eran Hirsch, Takos, Chanhyeong Lee, Sjukd00m and 4 more
    Reacted by ramtinq, David Nellessen and Simon
  18. lahirumaramba
    reopened this on Apr 9, 2021
  19. miksa commented on Dec 20, 2021

    @miksa
    miksa
    on Dec 20, 2021
    More actions

    Hi! Is there any update about this feature ? I saw a pull request to use new version of the google-auth api, would that fulfill prerequisites ?

    Reacted by David Nellessen and Paul Rudin
  20. guneemwelloeux commented on Feb 24, 2022

    @guneemwelloeux
    guneemwelloeux
    on Feb 24, 2022
    More actions

    Hello! I know the last comment wasn't left here long ago, but as it didn't get any answer, I'm posting another one.
    Has a timeline been agreed upon since April 2021, and if there is one, could you please let everyone know here?

    Many thanks!

    Reacted by Brad Reardon
  21. lahirumaramba commented on Feb 24, 2022

    @lahirumaramba
    lahirumaramba
    on Feb 24, 2022
    Member
    More actions

    Thank you again for your patience on this!
    This is a high priority task for us and we should start seeing the initial changes sometime in Q2/Q3 2022. I can't promise you a timeline for this feature but rest assured that this is something on our immediate roadmap for this year and you will see updates in the coming months.

    Reacted by JJFlash
    Reacted by al-stefanitsky-mozdor and Simon
    Reacted by William OLLIVIER and rhoboro
  22. jkyle109 commented on Aug 25, 2022

    @jkyle109
    jkyle109
    on Aug 25, 2022
    Contributor
    More actions

    Hey Folks, We just released v5.3.0 which added async support for the Cloud Firestore API. This is the first step into fulfilling this FR so please give it a try and let us know what you think!

    Reacted by Toni Alatalo, Alec Daling and Alessandro Facchin
    Reacted by Brad Reardon, Nelson Castillo, MeRuslan, Eran Hirsch and Alessandro Facchin
  23. antont commented on Feb 2, 2024

    @antont
    antont
    on Feb 2, 2024
    More actions

    Seems to be working well, we haven't used this under heavy load yet, though.

    I'm curious to hear how others are experiencing this, but AFAIK it's good and robust.

    We mostly use firestore and do async gcloud storage uploads too, so things are pretty good.

    Messages seems to be one thing missing? #639
    That would be actually nice to have.

    Reacted by Tarek Salama
  24. alexandermalyga commented on Dec 22, 2024

    @alexandermalyga
    alexandermalyga
    on Dec 22, 2024
    More actions

    Hi, are there any plans to add async support to the admin auth client? Thanks for the great work!

    Reacted by Alex Parubchishin, kukac and Lenormand Julien
    Reacted by KHELIFI Ahmed Aziz
  25. alex-paru commented on May 24, 2025

    @alex-paru
    alex-paru
    on May 24, 2025
    More actions

    Hi @lahirumaramba ! Just checking in - are there any updates or an ETA on this feature? Are there any blockers currently preventing progress?
    It’s been quite a while - over 8 years since the issue was created and 2.5 years since the last update - so any news or context would be greatly appreciated. Thanks in advance!

    Reacted by KHELIFI Ahmed Aziz, Bar Harel, Ivan Malison, kukac, Mike, Paul Stoker, Safa Arıman and Lenormand Julien
  26. hojjatabdollahi commented on Dec 4, 2025

    @hojjatabdollahi
    hojjatabdollahi
    on Dec 4, 2025
    More actions

    Is there any plan to add async support? Or is this a won't fix?

  27. Natim commented on Dec 5, 2025

    @Natim
    Natim
    on Dec 5, 2025
    More actions

    If you want async support, you should rely on google-cloud-firestore:

    from google.cloud.firestore_v1.async_client import AsyncClient
    
    db = AsyncClient()
    
    async def add_doc_async():
        doc_ref = db.collection("users").document()
        await doc_ref.set({"name": "Alice"})
    
  28. hojjatabdollahi commented on Dec 5, 2025

    @hojjatabdollahi
    hojjatabdollahi
    on Dec 5, 2025
    More actions

    @Natim Thank you. But does that work for auth too?

  29. Natim commented on Dec 5, 2025

    @Natim
    Natim
    on Dec 5, 2025
    More actions

    I haven't tried but, if it doesn't, alternatively you can use an async wrapper such as:

    import asyncio
    import firebase_admin
    from firebase_admin import credentials, auth
    
    cred = credentials.Certificate("service-account.json")
    firebase_admin.initialize_app(cred)
    
    # --- Blocking functions ------------------------------
    
    def verify_id_token_blocking(token: str):
        return auth.verify_id_token(token)
    
    def create_user_blocking(**kwargs):
        return auth.create_user(**kwargs)
    
    def get_user_blocking(uid: str):
        return auth.get_user(uid)
    
    def set_custom_claims_blocking(uid: str, claims: dict):
        return auth.set_custom_user_claims(uid, claims)
    
    # --- Async wrappers -----------------------------------
    
    async def verify_id_token_async(token: str):
        return await asyncio.to_thread(verify_id_token_blocking, token)
    
    async def create_user_async(**kwargs):
        return await asyncio.to_thread(create_user_blocking, **kwargs)
    
    async def get_user_async(uid: str):
        return await asyncio.to_thread(get_user_blocking, uid)
    
    async def set_custom_claims_async(uid: str, claims: dict):
        return await asyncio.to_thread(set_custom_claims_blocking, uid, claims)
    
    
    # --- Example usage inside async context ---------------
    
    async def main():
        user = await create_user_async(email="[email protected]", password="pw1234")
        print("User created:", user.uid)
    
        decoded = await verify_id_token_async("<token>")
        print("Token claims:", decoded)
    
        user2 = await get_user_async(user.uid)
        print("Fetched user:", user2.email)
    
    asyncio.run(main())
  30. Natim commented on Dec 5, 2025

    @Natim
    Natim
    on Dec 5, 2025
    More actions

    Apparently you can yes

    import asyncio
    import firebase_admin
    from firebase_admin import credentials, auth
    from google.cloud.firestore_v1.async_client import AsyncClient
    
    cred = credentials.Certificate("service-account.json")
    firebase_admin.initialize_app(cred)
    
    db = AsyncClient()
    
    async def get_user_data_from_token(id_token: str):
        decoded = auth.verify_id_token(token)
        uid = decoded["uid"]
        doc = await db.collection("users").document(uid).get()
        return doc.to_dict() if doc.exists else None
  31. lahirumaramba commented on Dec 9, 2025

    @lahirumaramba
    lahirumaramba
    on Dec 9, 2025
    Member
    More actions

    Firebase Admin Python SDK supports Firestore Async clients. See https://firebase.google.com/docs/firestore/quickstart#python_2

    The SDK also supports async counterparts for Messaging (send_each_async() and send_each_for_multicast_async()).

    We will continue to extend support for other services in the future. If you have requests for async support in a specific Firebase service please create a new FR covering that service. It helps us track progress instead of having a global FR for all the services/APIs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @lahirumaramba
    lahirumaramba

Labels

api: core

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.