Welcome to cottoncandy!

sugar for s3


What is cottoncandy?

A python scientific library for storing and accessing numpy array data on S3. This is achieved by reading arrays from memory and downloading arrays directly into memory. This means that you don’t have to download your array to disk, and then load it from disk into your python session.

This library relies heavily on boto3 (https://github.com/boto/boto3)


Clone the repo from GitHub and do the usual python install

git clone https://github.com/gallantlab/cottoncandy.git
cd cottoncandy
sudo python setup.py install

A configuration file will be saved under ~/.config/cottoncandy/options.cfg. Upon installation cottoncandy will try to find your AWS keys and store them in this file. See the default file for more configuration options.

Object and bucket permissions are set to authenticated-read by default. If you wish to keep all your objects private, modify the configuration file and set default_acl = private. See AWS ACL overview for more information on S3 permissions.

Getting started

Setup the connection (endpoint, access and secret keys can be specified in the configuration file instead):

>>> import cottoncandy as cc
>>> cci = cc.get_interface('my_bucket',

Storing numpy arrays

>>> import numpy as np
>>> arr = np.random.randn(100)
>>> s3_response = cci.upload_raw_array('myarray', arr)
>>> arr_down = cci.download_raw_array('myarray')
>>> assert np.allclose(arr, arr_down)

Storing dask arrays

>>> arr = np.random.randn(100,600,1000)
>>> s3_response = cci.upload_dask_array('test_dim', arr, axis=-1)
>>> dask_object = cci.download_dask_array('test_dim')
>>> dask_object
dask.array<array, shape=(100, 600, 1000), dtype=float64, chunksize=(100, 600, 100)>
>>> dask_slice = dask_object[..., :200]
>>> dask_slice
dask.array<getitem..., shape=(100, 600, 1000), dtype=float64, chunksize=(100, 600, 100)>
>>> downloaded_data = np.asarray(dask_slice) # this downloads the array
>>> downloaded_data.shape
(100, 600, 200)

Filesystem-like object browsing

>>> import cottoncandy as cc
>>> browser = cc.get_browser('my_bucket_name',
>>> browser.sweet_project.sub<TAB>
>>> browser.sweet_project.sub01_awesome_analysis_DOT_grp
<cottoncandy-group <bucket:my_bucket_name> (sub01_awesome_analysis.grp: 3 keys)>
>>> browser.sweet_project.sub01_awesome_analysis_DOT_grp.result_model01
<cottoncandy-dataset <bucket:my_bucket_name [1.00MB:shape=(10000)]>

Learn more:




Mar 30, 2020