Created
January 15, 2021 06:41
-
-
Save alecbw/a8d35b92c76346b8cd147136fd8f3ac6 to your computer and use it in GitHub Desktop.
get CSV from S3 Bucket as list of dictionaries
This file contains hidden or 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 | |
import csv | |
def get_csv_from_s3_as_list_of_dictionaries(bucket_name, filename): | |
s3_obj = boto3.client("s3").get_object(Bucket=bucket_name, Key=filename.lstrip("/"))["Body"] | |
return [{k:v for k, v in row.items()} for row in csv.DictReader(s3_obj.read().decode('utf-8').splitlines(True), skipinitialspace=True)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment