Skip to content

Storage

Storage

Google Cloud Storage

Source code in breathecode/services/google_cloud/storage.py
class Storage:
    """Google Cloud Storage"""

    client: storage.Client

    def __init__(self) -> None:
        credentials.resolve_credentials()
        self.client = self._get_client()

    @circuit
    def _get_client(self) -> storage.Client:
        """Get Google Cloud Storage client

        Returns:
            storage.Client: Google Cloud Storage client
        """
        return storage.Client()

    def file(self, bucket_name: str, file_name: str) -> File:
        """Get File object

        Args:
            bucket_name (str): Name of bucket in Google Cloud Storage
            file_name (str): Name of blob in Google Cloud Bucket

        Returns:
            File: File object
        """
        bucket = self.client.bucket(bucket_name)
        return File(bucket, file_name)

file(bucket_name, file_name)

Get File object

Parameters:

Name Type Description Default
bucket_name str

Name of bucket in Google Cloud Storage

required
file_name str

Name of blob in Google Cloud Bucket

required

Returns:

Name Type Description
File File

File object

Source code in breathecode/services/google_cloud/storage.py
def file(self, bucket_name: str, file_name: str) -> File:
    """Get File object

    Args:
        bucket_name (str): Name of bucket in Google Cloud Storage
        file_name (str): Name of blob in Google Cloud Bucket

    Returns:
        File: File object
    """
    bucket = self.client.bucket(bucket_name)
    return File(bucket, file_name)