Giter Club home page Giter Club logo

jnotebook_reader's Introduction

๐Ÿƒ jnotebook_reader

  • Browse and render Jupyter Notebooks from local, Amazon S3, Google Cloud Storage or MinIO
  • Register and access multiple directories(or buckets) at the same time
  • Show and allow to config ToC(Table of Contents) included in your Jupyter Notebook
  • Hide/show all codes in your Jupyter Notebook interactively
  • Generate a permanent link about your Jupyter Notebook
  • Download your Jupyter Notebook in one click

โ™ˆ Screenshots

screenshot
screenshot

โ™‰ Runtime Environment Requirement

python 3

โ™Š Quick Start

git clone https://github.com/line/jnotebook-reader
cd jnotebook-reader
pip install -r requirements.txt
python app.py

โ™‹ How to configure

lib/config.py

"default": {                                  # default config
    "server": {
        "port": 9088,                         # The port server listening on
        "root": "/jupyternb"                  # Context path, base url
    },
    "storage": { # Storage type
        "type": "local",                      # local or s3
        "directories": [                      # If type is local effective
            "/path/foo/bar/1",
            "/path/foo/bar/2"
        ],                                              
        "s3": {                               # s3 config, if type is s3 effective
            "endpoint": None,                 # s3 endpoint, if type is s3 required, if set with None would access to s3 global url
            "accessKey": "YOUR_ACCESS_KEY",   # optional, default; request header "Access-Key" could replace it
            "secretKey": "YOUR_SECRET_KEY",   # optional, default; request header "Secret-Key" could replace it
            "buckets": ["YOUR_BUCKET_NAME"],  # optional, default; request header "Bucket-Name" could replace it
        }
    },
    "logging": {
        "level": logging.DEBUG,
        "format": "%(asctime)s - %(name)s - %(lineno)d - %(levelname)s - %(message)s",
        "filename": "/path/foo/bar/access.log"
    }
}

How to configure for local storage

You can configure multiple directories to be accessed by the jnotebook-viewer at the same time. Depending on your preference, you can set it as list or dict.

1. "list" type

"directories": [
    "/path/foo/bar/1",
    "/path/foo/bar/2"
]

You can access it like:
http://localhost:9088/0
http://localhost:9088/1

2. "dict" type

"directories": {
    "a": "/path/foo/bar/1",
    "b": "/path/foo/bar/2"
}

You can access it like:
http://localhost:9088/a
http://localhost:9088/b

3. single directory

"directories": "/path/foo/bar/1"

You can access it like:
http://localhost:9088/ANY

How to configure for S3 storage

You can configure multiple buckets to be accessed by the jnotebook-reader at the same time. Depending on your preference, you can set it as list or dict.

1. "list" type

"buckets": [
    "bucket_name_1",
    "bucket_name_2"
]

You can access it like:
http://localhost:9088/0
http://localhost:9088/1

2. "dict" type

"buckets": {
    "a": "bucket_name_1",
    "b": "bucket_name_2"
}

You can access it like:
http://localhost:9088/a
http://localhost:9088/b

3. single bucket

"buckets": "bucket_name_1"

You can access it like:
http://localhost:9088/ANY

How to configure with environment variables

You can set configuration through environment variables. if environment variables set, the configuration file will be overwritten accordingly.

# Storage type, local or s3, default is local
JNOTEBOOK_READER_STORAGE_TYPE = "local"
# s3 endpoint, only for s3 storage type
JNOTEBOOK_READER_S3_ENDPOINT = ""
# s3 access key, only for s3 storage type
AWS_ACCESS_KEY_ID = ""
# s3 secret key, only for s3 storage type
AWS_SECRET_ACCESS_KEY = ""
# s3 bucket name, could set multiple, separated by ',' only for s3 storage type
JNOTEBOOK_READER_S3_BUCKET_NAME = ""
# local directories, could set multiple, separated by ',' only for local storage type
JNOTEBOOK_READER_DIR = ""

โ™Œ API Spec

Method

GET http://localhost:9088/:id/(:prefix|:key|:path)

Path Variable

Name Type Description
id string ID defined by user
prefix string S3 object prefix
key string S3 object key
path string Local file path

Headers

Name Type Description
Access-Key string S3 access key id
Secret-Key string S3 secret access key
Bucket-Name string S3 bucket name

Example

s3 with request headers

curl -X GET \
  http://localhost:9088/5e26886d36b28f778dddcf0f/folder/test.ipynb \
  -H 'access-key: your_access_key' \
  -H 'bucket-name: test_bucket_name' \
  -H 'secret-key: your_secret_key'

s3 with config buckets

curl -X GET http://localhost:9088/0/folder/test.ipynb

local

curl -X GET http://localhost:9088/1/folder/test.ipynb

โ™ Production

If you want to release jnotebook_reader as a production service, it is recommended that you install waitress-serve to manage your service.

git clone https://github.com/line/jnotebook-reader
cd jnotebook-reader
pip install -r requirements.txt
waitress-serve --call --listen=:9088 'app:create_app' &

โ™’ Docker

docker build -t jnotebook_reader -f docker/Dockerfile .
docker run -p 9088:9088 \
    -e JNOTEBOOK_READER_SERVER_PORT="9088" \
    -e JNOTEBOOK_READER_STORAGE_TYPE="s3" \
    -e JNOTEBOOK_READER_S3_ENDPOINT="S3_ENDPOINT" \
    -e AWS_ACCESS_KEY_ID="S3_ACCESS_KEY" \
    -e AWS_SECRET_ACCESS_KEY="S3_SECRET_KEY" \
    -e JNOTEBOOK_READER_S3_BUCKET_NAME="S3_BUCKET_NAME_1,S3_BUCKET_NAME_2" \
    -it --rm jnotebook_reader

โ™“ Kubernetes

# Rollout jnotebook_reader deployment on Kubernetes cluster ( all resources are created in jnotebook-reader namespace )
kubectl apply -f docker/deployment.yml

# Get jnotebook_reader port
The examples deploy a NodePort service, so you have to check for the port it is mapped to:

kubectl get svc -n jnotebook-reader

Use the second port you find in the output to access jnotebook_reader, for instance:

NAME                   TYPE       CLUSTER-IP     EXTERNAL-IP   PORT(S)          AGE
jnotebook-reader-svc   NodePort   172.19.66.29   <none>        9088:30693/TCP   25s

Type in browser -> http://{kubernetes_cluster_ip}:30693

# Destroy all resources
kubectl delete ns jnotebook-reader

โ˜ฎ๏ธ Contributing

Please see CONTRIBUTING.md for contributing to jnotebook-reader.

If you believe you have discovered a vulnerability or have an issue related to security, please DO NOT open a public issue. Instead, send us a mail to [email protected].

โ™Ž License

Copyright 2020 LINE Corporation

LINE Corporation licenses this file to you under the Apache License,
version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at:

   https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.

See LICENSE for more detail.

jnotebook_reader's People

Contributors

hechangqin avatar mars-martin-line avatar ricecooker avatar syleeeee avatar withsmilo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

jnotebook_reader's Issues

Unable to use buckets specified as dict

bucket = request.headers.get("Bucket-Name") \
or os.environ.get("JNOTEBOOK_READER_S3_BUCKET_NAME", "").split(",")[int(id)] \
or self.__bucket(id)

Whenlib/config.py uses a dict to specify buckets, the code above has a typecast exception casting a string to an int even when JNOTEBOOK_READER_S3_BUCKET_NAME is not used. As a result, buckets specified as a dict does not work currently in jnotebook_reader.

bug: Failed to run app.py on start

Hi, long time no see. :)
I'm trying to use the jnotebook_reader for internal jupyter notebook users, but I've met an error on starting app.py. I will create a pull request soon to fix this.

% python app.py
Traceback (most recent call last):
  File "app.py", line 16, in <module>
    from flask import Flask
  File "/opt/anaconda3/envs/jnotebook_reader_py38_2/lib/python3.8/site-packages/flask/__init__.py", line 14, in <module>
    from jinja2 import escape
ImportError: cannot import name 'escape' from 'jinja2' (/opt/anaconda3/envs/jnotebook_reader_py38_2/lib/python3.8/site-packages/jinja2/__init__.py)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.