A S3-backed ContentsManager implementation for Jupyter
Project description
S3Contents
A S3 and GCS backed ContentsManager implementation for Jupyter.
It aims to a be a transparent, drop-in replacement for Jupyter standard filesystem-backed storage system. With this implementation of a Jupyter Contents Manager you can save all your notebooks, regular files, directories structure directly to a S3/GCS bucket, this could be on AWS/GCP or a self hosted S3 API compatible like minio.
While there is some implementations of this functionality already available online [2] I wasn't able to make them work in newer Jupyter Notebook installations. This aims to be a better tested one by being highly based on the awesome PGContents[1].
Prerequisites
Write access (valid credentials) to an S3/GCS bucket, this could be on AWS/GCP or a self hosted S3 like minio.
Installation
$ pip install s3contents
Jupyter config
Edit ~/.jupyter/jupyter_notebook_config.py
by filling the missing values:
S3
from s3contents import S3ContentsManager
c = get_config()
# Tell Jupyter to use S3ContentsManager for all storage.
c.NotebookApp.contents_manager_class = S3ContentsManager
c.S3ContentsManager.access_key_id = <AWS Access Key ID / IAM Access Key ID>
c.S3ContentsManager.secret_access_key = <AWS Secret Access Key / IAM Secret Access Key>
c.S3ContentsManager.bucket = "<bucket-name>>"
Example for play.minio.io:9000
:
from s3contents import S3ContentsManager
c = get_config()
# Tell Jupyter to use S3ContentsManager for all storage.
c.NotebookApp.contents_manager_class = S3ContentsManager
c.S3ContentsManager.access_key_id = "Q3AM3UQ867SPQQA43P2F"
c.S3ContentsManager.secret_access_key = "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG"
c.S3ContentsManager.endpoint_url = "http://play.minio.io:9000"
c.S3ContentsManager.bucket = "s3contents-demo"
c.S3ContentsManager.prefix = "notebooks/test"
GCP
Note that the file ~/.config/gcloud/application_default_credentials.json
assumes a posix system
when you did gcloud init
from s3contents import GCSContentsManager
c = get_config(
c.NotebookApp.contents_manager_class = GCSContentsManager
c.GCSContentsManager.project = "<your-project>"
c.GCSContentsManager.token = "~/.config/gcloud/application_default_credentials.json"
c.GCSContentsManager.bucket = "<bucket-name>"
AWS IAM
It is also possible to use IAM Role-based access to the S3 bucket from an Amazon EC2 instance; to do that,
just leave access_key_id
and secret_access_key
set to their default values (None
), and ensure that
the EC2 instance has an IAM role which provides sufficient permissions for the bucket and the operations necessary.
Access local files
To access local file as well as remote files in S3 you can use pgcontents.
.
First:
pip install pgcontents
And use a configuration like this:
from s3contents import S3ContentsManager
from pgcontents.hybridmanager import HybridContentsManager
from IPython.html.services.contents.filemanager import FileContentsManager
c = get_config()
c.NotebookApp.contents_manager_class = HybridContentsManager
c.HybridContentsManager.manager_classes = {
# Associate the root directory with a PostgresContentsManager.
# This manager will receive all requests that don"t fall under any of the
# other managers.
"": S3ContentsManager,
# Associate /directory with a FileContentsManager.
"local_directory": FileContentsManager,
}
c.HybridContentsManager.manager_kwargs = {
# Args for root PostgresContentsManager.
"": {
"access_key_id": "access-key",
"secret_access_key": "secret-key",
"endpoint_url": "http://localhost:9000",
"bucket": "notebooks",
},
# Args for the FileContentsManager mapped to /directory
"local_directory": {
"root_dir": "/Users/drodriguez/Downloads",
},
}
See also
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file s3contents-0.1.11.tar.gz
.
File metadata
- Download URL: s3contents-0.1.11.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.7.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 846df246adb6c6abbed712b5be1ddd2c62fd06175f8e916c3813515c2877c6d4 |
|
MD5 | ac0af0789931248ab4f2f8ab2fcc45f7 |
|
BLAKE2b-256 | 3acc62e96c1ec6a295a848eff810120a2ea564a045b25c3ffd29c6d02b9cc705 |