GCS Class Documentation#

The GCS class provides methods to interact with Google Cloud Storage (GCS), allowing for uploading and downloading files.

class GCS(project_name, service_key=None)#

Initializes the GCS client with the specified project name and optional service key.

Parameters:
  • project_name (str) – The Google Cloud project name.

  • service_key (str, optional) – The path to the service account key file (optional).

upload(file_path, destination)#

Uploads a file to GCS.

Parameters:
  • file_path (str) – The path to the file to upload.

  • destination (str) – The destination path in GCS.

Example:

gcs_client = GCS('my-gcp-project')
gcs_client.upload_data('/local/path/to/file.txt', 'bucket-name/object-name.txt')
download(source, file_path)#

Downloads a file from GCS.

Parameters:
  • source (str) – The source path in GCS.

  • file_path (str) – The local path to save the downloaded file.

Example:

gcs_client = GCS('my-gcp-project')
gcs_client.download_data('bucket-name/object-name.txt', '/local/path/to/save/file.txt')

This module is responsible for creating a GCS client

class unicloud.gcs.GCS(project_name: str, service_key: str | None = None)#

Bases: CloudStorageFactory

GCS Cloud Storage

property client#

client.

create_client() Client#

create_client.

the returned client deals with everything related to the specific project. For Google Cloud Storage,

authenticating via a service account is the recommended approach. If you’re running your code on a Google Cloud environment (e.g., Compute Engine, Cloud Run, etc.), the environment’s default service account might automatically be used, provided it has the necessary permissions. Otherwise, you can set the GOOGLE_APPLICATION_CREDENTIALS environment variable to point to your service account JSON key file.

Returns#

google cloud storage client object

download(source, file_path)#

Download a file from GCS.

Parameters#

source: [str]

The source path in the cloud storage.

file_path: [str]

The path to save the downloaded file.

property project_id#

project_id.

upload(file_path: str, destination: str)#

Upload a file to GCS.

Parameters#

file_path: [str]

The path to the file to upload.

destination: [str]

The destination path in the cloud storage.