Google Objects
Thin, pythonic OO wrapper around Google's "google-api-python-client" library. Currently supports Python 3+
Installation
$ pip install google-objects
Usage
Requires a valid Google API Credentials object from Google's excellent oauth2lib library. For more information, visit here.
Google Drive v3
- Retrieve drive 'About' information:
from google_objects import DriveClient
gdrive = DriveClient(OAUTH2LIB_CREDS)
about = gdrive.get_about()
print(about.email)
print(about.name)
# prints link to profile photo
print(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'),
}
for file in files_by_type['folders']:
print(file.id)
print(file.name)
for file in files_by_type['spreadsheets']:
# prints list of parent folder IDs
print(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 view
permission = new_file.add_permission('myfriend@hotmail.com')
# print newly created permission information
print(permission.role, permission.type, permission.email)
Google Slides v1
- Retrieve presentation and loop through elements:
from google_objects import SlidesClient
gslides = SlidesClient(OAUTHLIB_CREDS)
presentation = gslides.get_presentation('PRESENTATION_ID')
# print slides attributes
for slide in presentation:
print(slide.id)
for element in slide: # 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')
for segment in shape.text:
print(segment.text)
- Batch update every cell in table:
# use with to perform batch updates in block
with presentation as pres:
table = pres.get_element_by_id('TABLE_ID')
for cell in table:
print(cell.location) # tuple containing cell location
for segment in cell.text:
# update cell
segment.text = 'UPDATED_VALUE'
Google Sheets v4
- Retrieve spreadsheet and loop through sheets:
from google_objects import SheetsClient
gsheets = SheetsClient(OAUTHLIB_CREDS)
spreadsheet = gsheets.get_spreadsheet('SPREADSHEET_ID')
for sheet in spreadsheet:
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')
for rng in named_range:
values = named_range.get_block()
- Update values block:
values = spreadsheet.get_range('SHEET_NAME!A:C')
# loop through rows
for i, row in enumerate(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)
Metadata
Release files for google_objects 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| google_objects-0.0.7.tar.gz | 16.1 kB | Without provenance | Details for google_objects-0.0.7.tar.gz |
Release files / google_objects-0.0.7.tar.gz
| Download URL | google_objects-0.0.7.tar.gz |
|---|---|
| Size | 16.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ce4ffb640d732843c010539ba255ba7eb48c6526abaea022620c06252ea64cfe
|
|
BLAKE2b-256 checksum How to use checksums |
00fcbad6a2172d81d81bd95d92e418ad6e79941425cd32c9cdb67a823a6bb1d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for google_objects 0.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.