Async Google API Client + Async Google Auth

omarryhan, updated 🕥 2023-02-15 10:14:07

Logo

Build Status Software License Code style: black Downloads Monthly Downloads

Aiogoogle

Async Google API client

Aiogoogle makes it possible to access most of Google's public APIs which include:

  • Google Calendar API
  • Google Drive API
  • Google Contacts API
  • Gmail API
  • Google Maps API
  • Youtube API
  • Translate API
  • Google Sheets API
  • Google Docs API
  • Gogle Analytics API
  • Google Books API
  • Google Fitness API
  • Google Genomics API
  • Google Cloud Storage
  • Kubernetes Engine API
  • And more

Documentation 📑

You can find the documentation here.

Issues

Token is not getting refreshed after its expired after around 1 hour

opened on 2022-11-19 09:46:12 by praveen-elastic

Issue: I've been executing a script to fetch all the objects from cloud storage. There are around a lot of objects present in the bucket. Observation: The script fetches half of the objects in around 1 hr and then raises the below-mentioned error. Traceback: Traceback (most recent call last): ``` "async for blob_page in blobs_full_request: File "~/aiogoogle/models.py", line 341, in _next_page_generator prev_res = await sess.send(next_req, full_res=True) File "~/aiogoogle/sessions/aiohttp_session.py", line 183, in send results = await schedule_tasks() File "~/aiogoogle/sessions/aiohttp_session.py", line 175, in schedule_tasks return await asyncio.gather(*tasks, return_exceptions=False) File "~/aiogoogle/sessions/aiohttp_session.py", line 157, in get_response response.raise_for_status() File "~/aiogoogle/models.py", line 453, in raise_for_status raise AuthError(msg=self.reason, req=self.req, res=self) aiogoogle.excs.AuthError:

Unauthorized

Content: {'code': 401, 'errors': [{'domain': 'global', 'location': 'Authorization', 'locationType': 'header', 'message': 'Invalid Credentials', 'reason': 'authError'}], 'message': 'Invalid Credentials'}

Request URL: https://storage.googleapis.com/storage/v1/b/.... ``` Question: Is there any other way to reset the access token present in the session_factory's send() method? or am I missing a step?

code snippet: blobs_full_request = await google_client.as_service_account( storage_client.objects.list(bucket=BUCKET), full_res=True, ) async for blob_page in blobs_full_request: yield blob_page

Possible issue: When pagination starts, if there are more pages to go through, the package fails to look for the validity of the access_token.

Add option to pass HTTP headers to API calls

opened on 2022-09-11 15:47:04 by kovan

Suggested implementation for #79. Tested and working.

Summary:

Each Google API response has a E-tag attached to it, which is included in the JSON response. If you save the response along with this E-tag, you can later check if the content of the response that you previously saved has has changed or not on the server, by adding the "If-None-Match" HTTP header to the API call. If the content has not changed, the API server answers with the code "304 not modifed".

This is a simple way to keep data retrieved from the API up to date.

The code of the API call would look like this:

python async with Aiogoogle( api_key= "your-api-key" ) as aiogoogle: api = await aiogoogle.discover("youtube", "v3") # etag hardcoded for the example, but this is supposed to be retrieved from the database or similar: etag = "vsu1KWWbOO-15Idit0GDZKgEFfo" result = await aiogoogle.as_api_key( api.videos.list( headers={"If-None-Match": etag}, part="snippet,contentDetails,statistics", id="YOUR_VIDEO_ID" ), full_res=True ) if result.status_code == 304: print("Resource was not modified since last check")

Can we provide a way to test the package end to end?

opened on 2022-08-16 12:37:48 by praveen-elastic

Great work with the repository, just a small request to add support for end-to-end testing. Like other open-source projects out there, can we get the endpoint for the server from OS so that the developer can overwrite such environment variable at the time of end-to-end testing?

Using pipe_to and pipe_from

opened on 2022-07-10 16:43:18 by Shmookoff

I can't really find anything in docs about the use of pipe_to. The only clarification I could find is this, where bytes get just printed out.

What buffer does it need? How do I use it? Can someone please clarify this for me.

DeprecationWarning: Inheritance class AiohttpSession from ClientSession is discouraged

opened on 2022-03-10 17:53:12 by RomeoDespres

Importing aiogoogle raises a DeprecationWarning. Usually we don't see it because Python filters it out, however when running tests with pytest it does show up and kinda messes up the output.

It's not really a big deal but I just thought it was worth flagging. Otherwise the lib is great!

You can see it by running the following:

bash $ python -Wd -c "import aiogoogle" C:\Python39\lib\abc.py:85: DeprecationWarning: Inheritance class AiohttpSession from ClientSession is discouraged cls = super().__new__(mcls, name, bases, namespace, **kwargs)

aiogoogle: 3.2.1 Python: 3.9.2 OS: Windows 10

Rename instantiated `Aiogoogle` objects in the docs to `api` to avoid name clashes between the aiogoogle module and aiogoogle object

opened on 2021-11-19 16:01:53 by omarryhan

For ref: https://github.com/omarryhan/aiogoogle/issues/81

Releases

v5.2.0 2023-02-15 10:13:01

bug fixes

  • fix a bug with URL escape character.

Thanks to

@KonstantAnxiety

v5.1.0 2023-01-11 14:45:38

Feature

Now you're able to configure safe parameters for URL encoding of path parameters being passed because they differ from one API to the other.

Thanks to

@jignesh-crest

v5.0.0 2022-12-20 21:13:10

Bugs / breaking change

Revert a previous change/bug-fix where path parameters with forward slashes "/" were being URL encoded, when they shouldn't. Now the encoding of forward slashes is optional again.

v4.5.0 2022-12-03 20:51:38

Features

  • Add support to discovery doc version 2 APIs

Thanks

to: @Phil305

v4.4.0 2022-11-21 09:17:01

Bug fixes

Now checking if token is fresh before sending next pagination request

Thanks

@neel004 !

v4.3.0 2022-08-08 18:09:07

Features

  • Add ability to chunk upload an AsyncIterable object using the pipe_from interface

Thanks

to: @erangalon !

Omar Ryhan

get 💩 ✅

GitHub Repository Homepage

async google-auth google-authentication discovery-service google-api google-cloud python-asyncio