Skip to main content

Framework for creating user-friendly Jupyter notebooks, accessible to both programming and non-programming users alike.

Project description

nbtools for JupyterLab

Binder Build Status Documentation Status Docker Pulls Join the chat at https://gitter.im/g2nb

nbtools is a framework for creating user-friendly Jupyter notebooks that are accessible to both programming and non-programming users. It is a core component of the g2nb project. The package provides:

  • A decorator which can transform any Python function into an interactive user interface.
  • A toolbox interface for encapsulating and adding new computational steps to a notebook.
  • Flexible theming and APIs to extend the nbtools functionality.
  • A WYSIWYG editor for markdown cells (provided as part of the accompanying juptyter-wyswyg package and coming soon to JupyterLab).

Requirements

  • JupyterLab >= 3.0
  • ipywidgets >= 7.0.0

Docker

A Docker image with nbtools and the full JupyterLab stack is available through DockerHub.

docker pull g2nb/lab
docker run --rm -p 8888:8888 g2nb/lab

Installation

JupyterLab support is in beta. For now you will need to either install the specific prerelease version from pip or create a development install from GitHub:

jupyter labextension install @jupyter-widgets/jupyterlab-manager
pip install nbtools==21.2b1

OR

# Install ipywidgets, if you haven't already
jupyter nbextension enable --py widgetsnbextension
jupyter labextension install @jupyter-widgets/jupyterlab-manager

# Clone the nbtools repository
git clone https://github.com/g2nb/nbtools.git
cd nbtools

# Install the nbtools JupyterLab prototype
pip install -e .
jupyter labextension develop . --overwrite
jupyter nbextension install --py nbtools --symlink --sys-prefix
jupyter nbextension enable --py nbtools --sys-prefix

Development

You can watch the source directory and run JupyterLab at the same time in different terminals to watch for changes in the extension's source and automatically rebuild the extension. To develop, run each of the following commands in a separate terminal.

jlpm run watch
jupyter lab

The jlpm command is JupyterLab's pinned version of yarn that is installed with JupyterLab. You may use yarn or npm in lieu of jlpm.

With the watch command running, every saved change will immediately be built locally and available in your running JupyterLab. Refresh JupyterLab to load the change in your browser (you may need to wait several seconds for the extension to be rebuilt).

By default, the jlpm run build command generates the source maps for this extension to make it easier to debug using the browser dev tools. To also generate source maps for the JupyterLab core extensions, you can run the following command:

jupyter lab build --minimize=False

Uninstall

pip uninstall nbtools

Getting Started

Let's start by writing a simple Hello World function and turning it into an interactive widget. Go ahead and install nbtools, launch Jupyter and open a new, blank notebook.

Once that's completed, let's write a basic function. The function below accepts a string and prints a brief message. By default, the message addresses the world. For good measure we will also add a docstring to document the function.

def say_hello(to_whom='World'):
    """Say hello to the world or whomever."""
    print('Hello ' + to_whom)

This is pretty basic Python and hopefully everything so far is familiar. Next, we will turn this function into an interactive widget with just an import statement and one line of code. Update your code to what is shown below and execute the cell.

import nbtools

@nbtools.build_ui
def say_hello(to_whom='World'):
    """Say hello to the world or whomever."""
    print('Hello ' + to_whom)

You should now see a widget containing a web form. This form will prompt for the value of the to_whom parameter. The docstring will also appear as a description near the top of the widget. Go ahead and change the to_whom value, then click the "Run" button. This will execute the function and print the results below. Meanwhile, the form will also collapse, making more room on your screen.

With the push of a button, you've run the say_hello function!

This is exciting, but it is far from the only feature of the nbtools package. You can edit markdown cells using a WYSIWYG editor, customize how your function displays, chain together multiple related functions, make widgets from existing third-party methods, create a library of interactive tools (just click the Tools button on the toolbar and you will see say_hello has already added itself) and more! Just see the documentation links below.

Features

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nbtools-22.3.0b2.tar.gz (2.5 MB view details)

Uploaded Source

Built Distribution

nbtools-22.3.0b2-py3-none-any.whl (4.9 MB view details)

Uploaded Python 3

File details

Details for the file nbtools-22.3.0b2.tar.gz.

File metadata

  • Download URL: nbtools-22.3.0b2.tar.gz
  • Upload date:
  • Size: 2.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.1 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for nbtools-22.3.0b2.tar.gz
Algorithm Hash digest
SHA256 6744cf0790379d7f8b5e2681202ee8ed62e81ef9d799423506c5b2afe550dd17
MD5 807123e601a5a7f199bd52ac8328b27a
BLAKE2b-256 5f7f5e4e4784b64b3e70d5e64d9fc3e0174c33a008282fd77a5e535005991c50

See more details on using hashes here.

File details

Details for the file nbtools-22.3.0b2-py3-none-any.whl.

File metadata

  • Download URL: nbtools-22.3.0b2-py3-none-any.whl
  • Upload date:
  • Size: 4.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.1 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2

File hashes

Hashes for nbtools-22.3.0b2-py3-none-any.whl
Algorithm Hash digest
SHA256 b89babc760e9f6b3bca4c704aa1c34cd563c3ccef96af231d67d5ef17c67213e
MD5 5330bae77cd92f89307557aff1ffd961
BLAKE2b-256 0f0dc4bd9bd27b0a7d2e1273d82a258fa43980619d00142a9f193b1344508a90

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page