Created
July 5, 2024 16:14
-
-
Save 2tony2/b4919e1e937c7cb38e192173efd85bd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import s3fs | |
def stream_data_from_s3(bucket_name, file_path, chunk_size=1024): | |
fs = s3fs.S3FileSystem() | |
with fs.open(f'{bucket_name}/{file_path}', 'rb') as file: | |
while chunk := file.read(chunk_size): | |
yield chunk | |
# Example usage | |
bucket_name = 'my-bucket' | |
file_path = 'large_file.csv' | |
for chunk in stream_data_from_s3(bucket_name, file_path): | |
# Process each chunk | |
print(chunk) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment