launchflow.gcp.gcs

GCSBucket

1
class GCSBucket(GCPResource[GCSBucketConnectionInfo])

A storage bucket in Google Cloud Storage.

Example usage:

1
import launchflow as lf
2
3
gcs = lf.gcp.GCSBucket("my-bucket")
4
5
# Quick utilities for reading and writing file contents
6
gcs.upload_from_string("file contents", "path/in/gcs/file.txt")
7
8
# You can also use the google-cloud-storage library directly
9
bucket = gcs.bucket()
10
bucket.blob("my-file").upload_from_filename("my-file")

__init__

1
def __init__(name: str, *, location="US") -> None

Create a new GCS Bucket resource.

Args:

  • name (str): The name of the bucket. This must be globally unique.
  • location (str): The location of the bucket. Defaults to "US".

bucket

1
def bucket()

Get the GCS bucket object returned by the google-cloud-storage library.

Returns:

upload_file

1
def upload_file(to_upload: Union[str, IO], bucket_path: str)

Uploads a file to the GCS bucket.

Args:

  • to_upload (Union[str, IO]): The file to upload. This can be a string representing the path to the file, or a file-like object.
  • bucket_path (str): The path to upload the file to in the bucket.

Example usage:

1
import launchflow as lf
2
3
bucket = lf.gcp.GCSBucket("my-bucket")
4
bucket.upload_file("my-file.txt", "my-file.txt")
5
bucket.upload_file(open("my-file.txt", "r"), "my-file.txt")

upload_from_string

1
def upload_from_string(to_upload: str, bucket_path: str)

Uploads a string to the GCS bucket.

Args:

  • to_upload (str): The string to upload.
  • bucket_path (str): The path to upload the string to in the bucket.

Example usage:

1
import launchflow as lf
2
3
bucket = lf.gcp.GCSBucket("my-bucket")
4
bucket.upload_from_string("hello", "hello.txt")

download_file

1
def download_file(bucket_path: str)

Downloads a file from the GCS bucket.

Args:

  • bucket_path (str): The path to the file in the bucket.

Example usage:

1
import launchflow as lf
2
3
bucket = lf.gcp.GCSBucket("my-bucket")
4
with open("my-file.txt", "w") as f:
5
f.write(bucket.download_file("my-file.txt"))