> Every page of the ganymede website is listed in https://eugo.io/docs/ganymede/llms.txt.

# Google Cloud API

> Work with the Google Cloud API. A Python demo notebook from ganymede.

Web page: https://eugo.io/docs/ganymede/demo_notebooks/geospatial/google/google_cloud_api/
Notebook: https://eugo.io/docs/ganymede/demo_notebooks/geospatial/google/google_cloud_api/google_cloud_api.ipynb (source: https://github.com/eugo-inc/ganymede/blob/main/demo_notebooks/geospatial/google/google_cloud_api.ipynb)

Description:
- Work with the Google Cloud API

Resources:
- https://gcloud.readthedocs.io/en/latest/storage-client.html
- https://googleapis.github.io/google-api-python-client/docs/start.html
- https://github.com/googleapis/google-api-python-client
- https://developers.google.com/drive/v3/reference/
- https://googleapis.github.io/google-api-python-client/docs/epy/index.html
- https://googleapis.github.io/google-api-python-client/docs/dyn/
- https://github.com/googleapis/google-cloud-python
- https://cloud.google.com/python/docs/reference
- https://googleapis.github.io/google-api-python-client/docs/dyn/drive_v3.html

## Environment variables

This notebook reads these environment variables. Set them before you start Jupyter:

- `GOOGLE_CLOUD_PROJECT`: your Google Cloud project id.
- `GCS_BUCKET`: a Google Cloud Storage bucket in that project that holds an object named `example.jpeg`.

## Example 1

Download an object as bytes and print the length of the object

```python
import os
from google.cloud import storage

storage_client = storage.Client(project=os.environ["GOOGLE_CLOUD_PROJECT"])
bucket = storage_client.bucket(os.environ["GCS_BUCKET"])
blob = bucket.blob('example.jpeg')
bts = blob.download_as_bytes()

print(len(bts))
```

## Example 2

Work with a Google service (like Google Drive, BigQuery, etc)

```python
from googleapiclient.discovery import build

with build('drive', 'v3') as service:
    print(service.about())
```

## Example 3

Work with a Google service

```python
from apiclient.discovery import build

service = build('admin', 'directory_v1')
print(service.customer())
```
