Created
November 28, 2020 13:24
-
-
Save monkut/a74b03da671faeecf97896221dda5e04 to your computer and use it in GitHub Desktop.
iterate a csv file in S3 from memory
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 boto3 | |
S3_CLIENT = boto3.client("s3") | |
def iterate_s3_csv(bucket: str, key: str) -> Generator: | |
with BytesIO() as bytesin: | |
S3_CLIENT.download_fileobj(bucket, key, bytesin) | |
bytesin.seek(0) | |
stringin = StringIO(bytesin.read().decode("utf8")) | |
reader = csv.DictReader(stringin) | |
yield from reader |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment