Skip to main content

Wrapper for Google's Python API.

Project description

googleapiutils2

Utilities for Google's v2 Python API. Currently supports sections of the following resources:

  • Drive: FilesResource, ...
  • Sheets: SpreadsheetsResource, ...
  • Geocoding

Quickstart

This project requires Python ^3.10 to run.

Several dependencies are needed, namely the aforesaid Google Python API, but also Google's oauth library, and requests. Pre-bundled for ease of use are the fairly monolithic google-api-stubs, which greatly improves the usage experience.

via poetry

Install poetry, then run

poetry install

And you're done.

Drive

...

Sheets

Simple example:

...
creds = get_oauth2_creds(client_config=config_path)
sheets = Sheets(creds=creds)

sheet_id = "id"
Sheet1 = SheetsValueRange(sheets, sheet_id, sheet_name="Sheet1")

rows = [
    {
        "Heyy": "99",
    }
]
Sheet1[2:3, ...].update(rows)

What the above does is: - Get the OAuth2 credentials from the client_config.json file - create a Sheets object thereupon. - Create a SheetsValueRange object, which is a wrapper around the spreadsheets.values API. - Update the range Sheet1!A2:B3 with the given rows.

Note the slicing syntax, which will feel quite familiar for any Python programmer.

SheetSlice

A SheetsValueRange object can be sliced in a similar manner to that of a Numpy array. The syntax is as follows:

slc = Sheet[rows, cols]

Wherein rows and cols are either integers, slices of integers (stride is not supported), strings (in A1 notation), or ellipses (...).

ix = SheetSlice["Sheet1", 1:3, 2:4] #  "Sheet1!B2:D4"
ix = SheetSlice["Sheet1", "A1:B2"]  #  "Sheet1!A1:B2"
ix = SheetSlice[1:3, 2:4]           #  "Sheet1!B2:D4"
ix = SheetSlice["A1:B2"]            #  "Sheet1!A1:B2"
ix = SheetSlice[..., 1:3]           #  "Sheet1!A1:Z3"

SheetSlice object can also be used as a key into a SheetsValueRange object, or a dictionary (to use in updating a sheet's range, for example). Further, a SheetsValueRange object can be sliced in a similar manner to that of a SheetSlice object, and also be used as a dictionary key.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

googleapiutils2-0.5.1.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

googleapiutils2-0.5.1-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file googleapiutils2-0.5.1.tar.gz.

File metadata

  • Download URL: googleapiutils2-0.5.1.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.2 Darwin/22.4.0

File hashes

Hashes for googleapiutils2-0.5.1.tar.gz
Algorithm Hash digest
SHA256 9b227f856e3f82c6ea47e723296cf50b6b83698acdd18ef64dce89fafa56c374
MD5 f7daccdbbd7fa5a1d09c8df7f450954a
BLAKE2b-256 0405d6128f57e7667c7971d9bd5608ad5cc53c776679b93848f0ec13df09dc4b

See more details on using hashes here.

File details

Details for the file googleapiutils2-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: googleapiutils2-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.2 Darwin/22.4.0

File hashes

Hashes for googleapiutils2-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aca9f34f95d4832dc5e0ba7930d3a260c2ee8b022c28a702b6e085a082abf771
MD5 4b5ed4f8efac9d80af3c1a9d9f54fb0c
BLAKE2b-256 5e4e4acd4e3de499c4fd86389ada45d1fa2a1397bd6e105f4ba9bb5bdf225030

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page