Datasets:
No need for AWS keys to download from a public bucket
#8
by
ocramz
- opened
The example code should be updated so folks who don't have an AWS account can still download this data. The following snippet makes unsigned (anonymous) requests to S3:
import os
import boto3
from botocore import UNSIGNED
from botocore.client import Config
from smart_open import open
from datasets import load_dataset
s3 = boto3.client('s3', region_name='us-east-1', config=Config(signature_version=UNSIGNED))
def download_contents(blob_id, src_encoding):
s3_url = f"s3://softwareheritage/content/{blob_id}"
with open(s3_url, "rb", compression=".gz", transport_params={"client": s3}) as s3bucket:
content = s3bucket.read().decode(src_encoding)
return {"content": content}
if __name__ == "__main__":
for r in load_dataset("bigcode/the-stack-v2-dedup", name='Python', split="train", streaming=True):
row = download_contents(r["blob_id"], r["src_encoding"])
print(row["content"])