google-api-python-client icon indicating copy to clipboard operation
google-api-python-client copied to clipboard

Asynchronous features (async, aiohttp, etc)

Open Vioshim opened this issue 4 years ago • 3 comments

Hello, good evening Google devs.

Is your feature request related to a problem? Please describe.

I've been a big fan of this API and being able to use it in python, however due to it being reliant on httplib2 and time.sleep (According to googleapiclient.http.HttpRequest).

Currently most programmers that use the API do proper threading practices in order to keep using this api without it being blocking in asynchornous context.

Describe the solution you'd like

By this reason I'd like to propose making classes that are designed for asynchronous code, those can rely on aiohttp.request which can get to be advantageous for this regard.

Describe alternatives you've considered

As stated before, the current alternative that I've been using with this library is asyncio's to_thread which helps to stop the blocking issue, but it's still not that adapted to the asynchronous context.

Additional context

Not much to add in this regard.

So that's pretty much my suggestion, have a great day.

Vioshim avatar Dec 15 '21 22:12 Vioshim

I'm working on this

ChynnaSyas avatar Jun 23 '24 02:06 ChynnaSyas

Question:

How can the Google Python API client library be enhanced to fully support asynchronous operations, ensuring non-blocking I/O and improved performance for high-throughput applications?

Hypothesis:

To effectively add asynchronous support to the Google Python API client library, the key design considerations and challenges must be addressed:

  • Asynchronous HTTP Requests: Challenge: Refactoring synchronous HTTP request functions to asynchronous without disrupting existing functionality.
  • Asynchronous Authentication: Challenge: Handling OAuth 2.0 authentication and token refresh operations asynchronously.
  • Concurrency: Challenge: Efficiently managing multiple concurrent API requests and handling rate limits imposed by Google APIs.
  • Error Handling: Challenge: Managing errors and retries in an asynchronous context, ensuring that the application remains resilient.
  • Backward Compatibility: Challenge: Maintaining backward compatibility with existing synchronous code to avoid breaking changes for current users.
  • Testing: Challenge: Ensuring the reliability and performance of the new asynchronous features through comprehensive testing.

ChynnaSyas avatar Jul 24 '24 18:07 ChynnaSyas

Allow me to attempt to answer each of these, as it's been 7 months:

Asynchronous HTTP Requests: new async methods can be named with Async at the end, with all sync method names remaining intact. A common approach for C# libraries.

Asynchronous Authentication: Simply using aiohttp with await will cover this. Not an issue.

Concurrency: No need for concurrent requests, just use aiohttp with awaits and it'll act just like the original sync calls, just with async support. If the dev wants concurrency they can do that on their own. Async enables this far easier than needing to enact multi-threading support the hard way.

Error Handling: Again, awaits make this easy.

Backward Compatibility: See point #1

Domush avatar Jan 29 '25 17:01 Domush

Any update on this one? it's kind of weird that in 2025 the official google-python interface still doesn't support async coding..

yovelcohen avatar Jun 03 '25 05:06 yovelcohen