Using Tools from Peak-SDK
S3 Tools
The Peak SDK provides S3 utilities for common Amazon S3 operations.
Upload files to S3
from peak.tools.s3 import upload
# Upload a file to S3
upload(local_path="./myfile.txt", s3_path="s3://my-bucket/path/to/myfile.txt")
Download files from S3
from peak.tools.s3 import download
# Download a file from S3
download(s3_path="s3://my-bucket/path/to/myfile.txt", local_path="./downloaded.txt")
Check if file exists in S3
from peak.tools.s3 import exists
# Check if a file exists
if exists("s3://my-bucket/path/to/myfile.txt"):
print("File exists!")
Copy files within S3
from peak.tools.s3 import copy
# Copy a file within S3
copy(
source="s3://my-bucket/source/file.txt",
destination="s3://my-bucket/destination/file.txt",
)
Iterate over S3 objects
from peak.tools.s3 import iterate
# Iterate over objects in an S3 path
for s3_object in iterate("s3://my-bucket/path/"):
print(f"Found: {s3_object.key}")