- Notifications
You must be signed in to change notification settings - Fork1
Wraps google-api-python-client for pythonic Google API interaction.
License
NotificationsYou must be signed in to change notification settings
condad/google-objects-python
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Thin, pythonic OO wrapper around Google's "google-api-python-client" library.Currently supports Python 3+
$ pip install google-objects
Requires a valid Google API Credentials object from Google's excellent oauth2lib library. For more information, visithere.
- Retrieve drive 'About' information:
fromgoogle_objectsimportDriveClientgdrive=DriveClient(OAUTH2LIB_CREDS)about=gdrive.get_about()print(about.email)print(about.name)# prints link to profile photoprint(about.photo)# ...
- List files in drive by type:
files_by_type= {'slides':gdrive.list_files('presentation'),'folders':gdrive.list_files('folder'),'spreadsheets':gdrive.list_files('spreadsheets'),}forfileinfiles_by_type['folders']:print(file.id)print(file.name)forfileinfiles_by_type['spreadsheets']:# prints list of parent folder IDsprint(file.parents)# ...
- Copy and share file:
file=gdrive.get_file('FILE_ID')new_file=file.copy('NEW_FILE_NAME', ['PARENT_FOLDER_1','PARENT_FOLDER_2'])# allow myfriend@hotmail.com to viewpermission=new_file.add_permission('myfriend@hotmail.com')# print newly created permission informationprint(permission.role,permission.type,permission.email)
- Retrieve presentation and loop through elements:
fromgoogle_objectsimportSlidesClientgslides=SlidesClient(OAUTHLIB_CREDS)presentation=gslides.get_presentation('PRESENTATION_ID')# print slides attributesforslideinpresentation:print(slide.id)forelementinslide:# equivalent to 'for element in presentation.elements()'print(element.type)# Shape, Table, etc
- Check text in shape:
shape=presentation.get_element_by_id('SHAPE_ID')forsegmentinshape.text:print(segment.text)
- Batch update every cell in table:
# use with to perform batch updates in blockwithpresentationaspres:table=pres.get_element_by_id('TABLE_ID')forcellintable:print(cell.location)# tuple containing cell locationforsegmentincell.text:# update cellsegment.text='UPDATED_VALUE'
- Retrieve spreadsheet and loop through sheets:
fromgoogle_objectsimportSheetsClientgsheets=SheetsClient(OAUTHLIB_CREDS)spreadsheet=gsheets.get_spreadsheet('SPREADSHEET_ID')forsheetinspreadsheet:print(sheet.id,sheet.title)
- Get sheet by name and return its full block of values:
sheet=spreadsheet['Sheet 1']values=sheet.values()
- Get named range value block:
named_ranges=spreadsheet.named_ranges('SHEET_NAME!A:C')forrnginnamed_range:values=named_range.get_block()
- Update values block:
values=spreadsheet.get_range('SHEET_NAME!A:C')# loop through rowsfori,rowinenumerate(values):values[i]= [1,2,3]print(row)values.update()# you can also use the slice syntax for updating..values[2:5]= [[1,2,4], [4,5,6], [6,7,8]]values.update()
- Append to values block:
to_append= [[1,2,3], [4,5,6]]values.append(to_append)
About
Wraps google-api-python-client for pythonic Google API interaction.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
No releases published
Packages0
No packages published
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.