Cloud storage
Cloud storage
π Datasets supports access to cloud storage providers through a fsspec FileSystem implementations. You can save and load datasets from any cloud storage in a Pythonic way. Take a look at the following table for some example of supported cloud storage providers:
This guide will show you how to save and load datasets with any cloud storage. Here are examples for S3, Google Cloud Storage, Azure Blob Storage, and Oracle Cloud Object Storage.
Set up your cloud storage FileSystem
Amazon S3
Install the S3 FileSystem implementation:
Copied
>>> pip install s3fsDefine your credentials
To use an anonymous connection, use anon=True. Otherwise, include your aws_access_key_id and aws_secret_access_key whenever you are interacting with a private S3 bucket.
Copied
Create your FileSystem instance
Copied
Google Cloud Storage
Install the Google Cloud Storage implementation:
Copied
Define your credentials
Copied
Create your FileSystem instance
Copied
Azure Blob Storage
Install the Azure Blob Storage implementation:
Copied
Define your credentials
Copied
Create your FileSystem instance
Copied
Oracle Cloud Object Storage
Install the OCI FileSystem implementation:
Copied
Define your credentials
Copied
Create your FileSystem instance
Copied
Load and Save your datasets using your cloud storage FileSystem
Download and prepare a dataset into a cloud storage
You can download and prepare a dataset into your cloud storage by specifying a remote output_dir in download_and_prepare. Donβt forget to use the previously defined storage_options containing your credentials to write into a private cloud storage.
The download_and_prepare method works in two steps:
it first downloads the raw data files (if any) in your local cache. You can set your cache directory by passing
cache_dirto load_dataset_builder()then it generates the dataset in Arrow or Parquet format in your cloud storage by iterating over the raw data files.
Load a dataset builder from the BOINC AI Hub (see how to load from the BOINC AI Hub):
Copied
Load a dataset builder using a loading script (see how to load a local loading script):
Copied
Use your own data files (see how to load local and remote files):
Copied
It is highly recommended to save the files as compressed Parquet files to optimize I/O by specifying file_format="parquet". Otherwise the dataset is saved as an uncompressed Arrow file.
You can also specify the size of the shards using max_shard_size (default is 500MB):
Copied
Dask
Dask is a parallel computing library and it has a pandas-like API for working with larger than memory Parquet datasets in parallel. Dask can use multiple threads or processes on a single machine, or a cluster of machines to process data in parallel. Dask supports local data but also data from a cloud storage.
Therefore you can load a dataset saved as sharded Parquet files in Dask with
Copied
You can find more about dask dataframes in their documentation.
Saving serialized datasets
After you have processed your dataset, you can save it to your cloud storage with Dataset.save_to_disk():
Copied
Remember to define your credentials in your FileSystem instance fs whenever you are interacting with a private cloud storage.
Listing serialized datasets
List files from a cloud storage with your FileSystem instance fs, using fs.ls:
Copied
Load serialized datasets
When you are ready to use your dataset again, reload it with Dataset.load_from_disk():
Copied
Last updated