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 — asyncio support · Issue #3103 · googleapis/google-cloud-python

asyncio support #3103

New issue
Copy link
New issue
Copy link
Closed
Closed
asyncio support#3103
Copy link
Assignees
lukesneeringer
Labels
type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Description

@graingert
graingert
opened on Mar 6, 2017
Issue body actions

I want to use google-cloud-python in a Sanic web service, however I'm having to use run_in_executor() to use this library without stalling the eventloop.

This is much less efficient than an Asyncio native client.

Reacted by Sacha, Alex, Jack Crawford, Thomas Cellerier, Joshua Hendinata, Clark Zinzow, Sami, af-dk, Denis, Marco and 21 more

Activity

Next
  1. graingert commented on Mar 6, 2017

    @graingert
    graingert
    on Mar 6, 2017
    Author
    More actions

    @jonparrott it would be possible to support python 2.x and python 3.x with various event loops from the same source by using a custom deferred, future or IOAction implementation.

  2. theacodes commented on Mar 6, 2017

    @theacodes
    theacodes
    on Mar 6, 2017
    Contributor
    More actions

    This might be possible once we exorcise httplib2 from this project. @lukesneeringer

  3. lukesneeringer commented on Mar 6, 2017

    @lukesneeringer
    lukesneeringer
    on Mar 6, 2017
    Contributor
    More actions

    That sounds right to me (and that has moved up in priority slightly).

    Tagging #1998 for reference.

  4. lukesneeringer
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    Status: Acknowledged
    status: blockedResolving the issue is dependent on other work.
    on Mar 6, 2017
  5. graingert commented on Mar 6, 2017

    @graingert
    graingert
    on Mar 6, 2017
    Author
    More actions

    the core code would use Action composition:

    return get_url(xys).map(process_request).flat_map(make_another_request)

    Then there could be various, pluggable http transport implementations, that would take an Action instance and return a Future from various event systems (asyncio, twisted), or even use blocking IO.

  6. graingert commented on Mar 8, 2017

    @graingert
    graingert
    on Mar 8, 2017
    Author
    More actions
    import asyncio
    import functools
    
    
    class AsyncIOAction(object):
        def __init__(self, fn):
            this.exec = fn
    
        def map(self, fn):
            @functools.wraps(fn)
            async def exec():
                value = await self.exec()
                return fn(value)
    
            return AsyncIOAction(exec)
    
        def flat_map(self, fn):
            @functools.wraps(fn)
            async def exec():
                value = await self.exec()
                return await fn(value).exec()
    
            return AsyncIOAction(exec)
    
        @classmethod
        def all(items):
            async def exec():
                return await asyncio.wait([x.exec() for x in items])
    
            return AsyncIOAction(exec)
    
    def aiohttp_action(request):
        async def exec():
            return await aiohttp.request(**request)
    
        return AsyncIOAction(exec)
            
    # blocking.py
    import functools
    
    class BlockingIOAction(object):
        def __init__(self, fn):
            this.exec = fn
    
        def map(self, fn):
            @functools.wraps(self, fn)
            def exec():
                value = self.exec()
                return fn(value)
            return BlockingIOAction(exec)
    
        def flat_map(self, fn):
            @functools.wraps(fn)
            def exec():
                value = self.exec()
                return fn(value).exec()
            
            return BlockingIOAction(exec)
    
        @classmethod
        def all(items):
            def exec():
                return [x.exec() for x in items]
    
            return BlockingIOAction(exec)
    
    def requests_action(request): # or httplib2 etc.
        def exec():
            requests.request(**request)
    
        return BlockingIOAction(exec)
    
    # twisted.py
    
    class TwistedIOAction(object):
        ...

    Should be pretty easy with twisted deferred too. Idea being, calling code would choose an IO type, configure the google cloud platform library appropriately, call a method on some API endpoint and then be able to call .exec() on the returned action. The calling code would then be able to receive the value, await and receive the value, or yield it in twisted inline callbacks.

  7. graingert commented on Mar 8, 2017

    @graingert
    graingert
    on Mar 8, 2017
    Author
    More actions

    Here's how you might to inline callbacks: https://gist.github.com/graingert/ca6cdd5d9ae2e18ca917b4594ac8a633#file-asyncio_and_blocking_io-py-L141-L148

  8. graingert commented on Mar 8, 2017

    @graingert
    graingert
    on Mar 8, 2017
    Author
    More actions

    inside google code platform:

    def some_api_method(IOAction, ham, spam):
        @IOAction.inline_callbacks
        def _some_api_method():
            v = yield some_other_method(IOAction, ham)
            v2 = yield another_method(IOAction, spam, v)
            Return(v + v2)
            
    return _some_api_method()

    In some calling code:

    async def async_caller():
        await some_api_method(AsyncIOAction, ham="ham", spam="spam").exec()
    
    def blocking_caller():
        some_api_method(BlockingIOAction, ham="ham", spam="spam").exec()
  9. graingert commented on Jul 24, 2017

    @graingert
    graingert
    on Jul 24, 2017
    Author
    More actions

    of course https://pypi.python.org/pypi/txaio might be a better way of implementing it.

  10. theacodes commented on Jul 24, 2017

    @theacodes
    theacodes
    on Jul 24, 2017
    Contributor
    More actions

    @graingert oh that's super interesting. However, this seems to re-enforce the fact that we can't really support this without breaking our public interface and without seriously re-thinking all of our internals. We'd have to start from scratch with this in mind. :/

  11. graingert commented on Jul 24, 2017

    @graingert
    graingert
    on Jul 24, 2017
    Author
    More actions

    @jonparrott with crossbario/txaio#113 and crossbario/txaio#110

    you probably won't have to change that much.

    And you'd be able to keep the same public api for people using requests.

  12. theacodes commented on Jul 24, 2017

    @theacodes
    theacodes
    on Jul 24, 2017
    Contributor
    More actions

    inlinecallbacks would help, but this is an enormous undertaking and a lot of our code that deals with IO is non-trivial (resumable-media).

    I'm open to doing this, but from my perspective it seems like the tooling isn't quite ready and it would take an enormous amount of engineering effort to get all of our plumbing ready- plus, we have a consider how gRPC plays into all this.

  13. dhermes commented on Jul 24, 2017

    @dhermes
    dhermes
    on Jul 24, 2017
    Contributor
    More actions

    FWIW, resumable-media would be the easiest thing of all to add support for because the actual I/O is "isolated" (I took the sans-I/O approach when writing it)

  14. 16 remaining items

  15. vladyslav2 commented on Jul 31, 2018

    @vladyslav2
    vladyslav2
    on Jul 31, 2018
    More actions

    @theacodes why do you believe supporting python 3 will be so significant big task?
    Are you willing to accept help from a community? I just check iot-core (stuff that i'm interested) and most of calls based on the paho.mqtt.python library which does support asyncio.
    So, i'm expecting I can port google-cloud-python/iot in few days since you have tests coverage

  16. theacodes commented on Jul 31, 2018

    @theacodes
    theacodes
    on Jul 31, 2018 via email
    Contributor
    More actions
    It's not that supporting python 3 is a significant task (we *do* support Python 3 after all), it's that maintaining 2 separate, divergent codebases for 40+ libraries isn't feasible. It's much more realistic for us to wait until we can remove 2.7 support. One of the reasons these libraries are open so is precisely to empower users to fork and extend as much as they want. So you're welcome to do so, just note that any support for that will be best-effort.
    …
    On Mon, Jul 30, 2018, 5:55 PM Vladysav Tarasenko ***@***.***> wrote: @theacodes <https://github.com/theacodes> why do you believe supporting python 3 will be so significant big task? Are you willing to accept help from a community? I just check iot-core (stuff that i'm interested) and most of calls based on the paho.mqtt.python library which does support asyncio. So, i'm expecting I can port google-cloud-python/iot in few days since you have tests coverage — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub <#3103 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAPUc6gh7LxtKsCRLLiYaydryDgdpuNHks5uL6r6gaJpZM4MUZWv> .
  17. syenchuk commented on Dec 19, 2018

    @syenchuk
    syenchuk
    on Dec 19, 2018
    More actions

    Please drop support for 2.7 now and add asyncio support :)
    Blocking networking calls is such a slow, has-been thing…

    Reacted by Vladyslav Tarasenko, Jonathan Striebel, Alex, Britton Winterrose, Moe-Kite, Maz, Yury Zhuravlev, Santiago Valdarrama, Derek Hao Hu, QaisarTanvir and 30 more
  18. rubik commented on Aug 7, 2019

    @rubik
    rubik
    on Aug 7, 2019
    More actions

    What is the status of this issue? Will it be fixed in the near future?

  19. tseaver commented on Aug 7, 2019

    @tseaver
    tseaver
    on Aug 7, 2019
    Contributor
    More actions

    @rubik Dropping 2.7 support is scheduled for Q1 2020. Adding asyncio support will be a major effort, but the relative priority for it isn't set, AFAIK.

    Reacted by Michele Lacchia, af-dk, Denis, Gary Oberbrunner, Yixi Zhang, Malar Kannan, min(max), Adam Eury, Chanhyeong Lee, Jacob Tomlinson and 1 more
  20. 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 as it is mentioned as a blocker for firebase/firebase-admin-python#104 ?
    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.

    Reacted by Adam Serafini
  21. software-dov commented on Jun 3, 2020

    @software-dov
    software-dov
    on Jun 3, 2020
    Contributor
    More actions

    API core is adding asyncio support right now (see here for details), but it's tough to say how long before client libraries providing asynchronous interfaces will be available.

    Reacted by Kamyar, Chanhyeong Lee, Akarsh and mrkiril94
    Reacted by Kamyar, Luke Holroyd, Chanhyeong Lee and Sam Millar
  22. JustinBeckwith
    assigned
    lukesneeringer
    on Feb 1, 2021
  23. ntoshev commented on Mar 17, 2021

    @ntoshev
    ntoshev
    on Mar 17, 2021
    More actions

    This is sorely needed, @lukesneeringer. An update will be greatly appreciated.

    I'm trying to work it around using https://github.com/talkiq/gcloud-aio

    Reacted by Peter Whidden and Akarsh
  24. NoamNol commented on Aug 8, 2021

    @NoamNol
    NoamNol
    on Aug 8, 2021
    More actions

    What do you think about Aiogoogle?

    Reacted by Andres and Chris Walker
  25. adriangb commented on Apr 17, 2022

    @adriangb
    adriangb
    on Apr 17, 2022
    More actions

    FWIW one workaround I've been using is generating presigned URLs for myself and then using them with httpx. But that compounds with other issues, namely #922. Python 2 has been EOL for 2 years now.

  26. zagfai commented on Jun 9, 2022

    @zagfai
    zagfai
    on Jun 9, 2022
    More actions

    We make our lib which support asyncio for spanner open source: https://pypi.org/project/aspanner/

  27. karthikv2k commented on Dec 4, 2024

    @karthikv2k
    karthikv2k
    on Dec 4, 2024
    More actions

    How is a one of top 3 cloud providers not supporting async python SDK! this is a big miss.

    Reacted by Mykola Morozov and Panwen Wang
  28. parthea
    added a commit that references this issue on Nov 22, 2025

    docs: add samples from bigtable (#38)

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

Metadata

Metadata

Assignees

  • @lukesneeringer
    lukesneeringer

Labels

type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

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.