Google Cloud Storage

Accessing a Google Cloud Storage (GCS) with the shell tool gsutil.

Installation

Use extras google-cloud-storage to install all required packages.

$ pip install mara-storage[google-cloud-storage]

You need to install gsutil. Take a look at Install gsutil.

Configuration examples

import pathlib
import mara_storage.storages
mara_storage.config.storages = lambda: {
    'data': mara_storage.storages.GoogleCloudStorage(
        bucket_name='my-gcs-bucket',
        project_id='<gcloud-project-id>',
        service_account_file='service-account.json'),
}


API reference

This section contains database specific API in the module.

Configuration

class mara_storage.storages.GoogleCloudStorage(bucket_name: str, project_id: Optional[str] = None, location: Optional[str] = None, service_account_file: Optional[str] = None, service_account_info: Optional[dict] = None)
__init__(bucket_name: str, project_id: Optional[str] = None, location: Optional[str] = None, service_account_file: Optional[str] = None, service_account_info: Optional[dict] = None)

Connection information for a Google Cloud Storage bucket

Parameters
  • bucket_name – name of the GCS bucket

  • project_id – Google Cloud project ID for new buckets

  • location – Default geographic location to use when creating buckets

  • service_account_file – The name of the private key file provided by Google when creating a service account. (it’s a JSON file).

  • service_account_info – The (parsed JSON) content of a service account file (use when you don’t want to provide a service_account_file)

property base_uri

Returns the base URI for the storage bucket

build_uri(path: str)

Returns a URI for a path on the storage