API Reference¶
This section provides detailed API documentation for all classes and methods in Conflux S3 Utils.
S3Uri¶
- class conflux_s3_utils.S3Uri(bucket, path)[source]¶
A type-safe representation of an S3 URI.
- static from_str(s3_uri_str)[source]¶
Parse an S3 URI string into an S3Uri object. S3 URI format:
s3://bucket_name/path/to/object
S3Client¶
- class conflux_s3_utils.S3Client(client=None)[source]¶
A S3 client that interacts with S3 using type-safe
S3Uriobjects and provides convenient methods for common operations.- Parameters:
client (Boto3S3Client | None)
- __init__(client=None)[source]¶
Initialize an S3Client. If
clientis not provided, a default boto3 S3 client will be created- Parameters:
client (Boto3S3Client | None)
- open(s3uri, mode='rb')[source]¶
Open an S3 object as a file-like object using fsspec. Note that this can be used with a context manager:
s3 = S3Client() with s3.open(s3uri) as f: # Do stuff with `f`. # It will automatically be closed when exiting the block.
- open_local(s3uri, mode='rb', multipart_chunksize=8388608)[source]¶
Interact with an object in S3 by opening a corresponding file locally.
With read mode (
modecontains “r”), the object is downloaded from S3 into a temporary directory and then a file handle to the local file is provided. The file and the temporary directory are cleaned up when the context manager exits.With write mode (
modecontains “w”), a file is created in a temporary directory and a file handle to the local file is provided. Upon exiting the context manager, the file is uploaded to S3. The file and temporary directry are cleaned up when the context manager exits.
- list_objects(s3uri, recursive=False)[source]¶
List objects under the given S3 URI, assuming it is a “directory”. If
recursiveisFalse, only list objects directly under the given path.
- upload_file(filepath, s3uri, multipart_chunksize=8388608)[source]¶
Upload a file to the specified S3 URI.
- download_file(s3uri, filepath, multipart_chunksize=8388608)[source]¶
Download a file from the specified S3 URI.