launchflow.aws.s3

S3Bucket

1
class S3Bucket(Resource[S3BucketConnectionInfo])

A S3 Bucket resource.

Attributes:

  • name (str): The name of the bucket. This must be globally unique.
  • region (str): The region of the bucket. Defaults to the environment default.

Example usage:

1
import launchflow as lf
2
bucket = lf.aws.S3Bucket("my-bucket")
3
bucket.blob("my-file").upload_from_filename("my-file")

bucket

1
def bucket()

Get the AWS bucket resource returned by the boto3 library.

Returns:

upload_file

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

Uploads a file to the S3 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
bucket = lf.aws.S3Bucket("my-bucket")
3
bucket.upload_file("my-file.txt", "my-file.txt")
4
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 S3 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.aws.S3Bucket("my-bucket")
4
bucket.upload_from_string("hello", "hello.txt")

download_file

1
def download_file(bucket_path: str)

Downloads a file from the S3 bucket.

Args:

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

Example usage:

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