Skip to content

Instantly share code, notes, and snippets.

@koepnick
Created January 1, 2021 21:44
Show Gist options
  • Save koepnick/5672dd3c0593f8c6cd102242a48510a4 to your computer and use it in GitHub Desktop.
Save koepnick/5672dd3c0593f8c6cd102242a48510a4 to your computer and use it in GitHub Desktop.
Connecting Colab to an external storage provider
Display the source blob
Display the rendered blob
Raw
# You only need ro run the install command once per kernel change
!pip install s3fs
import s3fs
fs = s3fs.S3FileSystem(
anon = False,
key = 'YOURKEY',
secret = 'YOURSECRET',
client_kwargs = {
'endpoint_url': 'https://some.s3.provider/'
}
)
# This is a silly example that eschews elegance for clarity
file_list = fs.listdir('/some/path')
file_object = file_list[0]
file_data = fs.open(file_object['Key'])
# Now treat it as a binary byte stream
from PIL import Image
png = Image.open(image_data)
display(png)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment