Skip to main content

google-api-helper Python Google API helper

google-api-helper helps streamline access to google apis including authentication using oauth2 and factory methods to create an API service. I.e. creating a compute API service is not to bad but still needs some code:

import googleapiclient.discovery
from oauth2client.service_account import ServiceAccountCredentials

credentials = ServiceAccountCredentials.from_json_keyfile_name("service_account.json", ["https://www.googleapis.com/auth/compute"])
compute = googleapiclient.discovery.build('compute', 'v1', credentials=credentials)

With google-api-helper that’s a oneliner:

from googleapi import GoogleApi
compute = GoogleApi.compute().with_service_account_file("service_account.json")

also using the OAUTH2 flow is simple

from googleapi import GoogleApi
compute = GoogleApi.compute().with_oauth2_flow("client_secret.json")

python-google-api-client also got retries for server errors included, but not for rate limiting. Therefore every API call you make needs to implement an exponential backoff. This is automatically done by using google-api-helper.

from googleapi import GoogleApi
compute = GoogleApi.compute().with_oauth2_flow("client_secret.json")
# directly using the api service without retries
compute.service.instances().list(project="my-gcp-project", zone="europe-west1-d").execute()
# wrapper including retries for rate limiting and server side errors
compute.instances().list(project="my-gcp-project", zone="europe-west1-d").execute()

Installation

Add google-api-helper to your requirements.txt or your module requirements or install via pip:

pip install google-api-helper

Quickstart

Import GoogleApi in your python code

from googleapi import GoogleApi

Create the api from a factory method or specify it by yourself:

compute = GoogleApi.compute()
drive = GoogleApi.drive()
gmail = GoogleApi("gmail", "v1", ["https://mail.google.com/"])

Authenticate with oauth2

# use Compute Engine or App Engine default credentials
compute.with_application_credentials()
# use a service account to access a users drive
drive.with_service_account_file("service_account.json", "test@example.com")
# or run a oauth2 flow to ask the user for credentials
gmail.with_oauth2_flow("client_secret.json")

And call the api

instances = compute.instances().list(project="project-id", zone="europe-west1-d").execute()
drive_files = drive.files().list(q="name='test'").execute()
messages = gmail.users().messages().list(userId="me").execute()

Building and publishing

python setup.py bdist_wheel --universal
python -m twine upload dist/*

Metadata

Release files for google-api-helper 0.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for google-api-helper 0.3.1
File Interpreter ABI Platform
google_api_helper-0.3.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Release files / google_api_helper-0.3.1-py2.py3-none-any.whl

Download URL google_api_helper-0.3.1-py2.py3-none-any.whl
Size 19.6 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
7a961f5274f848403b95ccd4064ad377581f3eeffa94b816602aadbdbb71f520
BLAKE2b-256 checksum
How to use checksums
3bcc17a3bf92d9158e8e59c98f4ccd8c2b25e96ceebbebb7e5e9abf2e8101620
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Security for google-api-helper 0.3.1

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page