Skip to main content

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.

Looking for classic Jupyter Notebook support?

Jupyter Notebook support is available, albeit not in active development. You can find it in its own branch. Just click here!

Requirements

  • JupyterLab >= 3.0
  • ipywidgets >= 7.5.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

At the moment you may install a prerelease version from pip or create a development install from GitHub:

pip install --pre nbtools

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

If installing from GitHub, before nbtools will load in your JupyterLab environment, you'll also need to build its labextension (see Development below).

Development

To develop with nbtools, you will need to first install npm or yarn, as well as install nbtools' dependencies. One way to do this is through conda. An example is given below. Run these commands within the top-level directory of the repository.

conda install npm.  # Install npm
npm install         # Install package requirements
npm run build       # Build the package
jupyter lab build   # Build JupyterLab with the extension installed

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

Metadata

Release files for nbtools 24.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nbtools 24.8.0
File Size Uploaded
nbtools-24.8.0.tar.gz 67.6 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for nbtools 24.8.0
File Interpreter ABI Platform
nbtools-24.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 74.5 MB

Release files / nbtools-24.8.0.tar.gz

Download URL nbtools-24.8.0.tar.gz
Size 67.6 MB
Tags Source
SHA-256 checksum
How to use checksums
5c1bf45efba057a2f67b767160d271e7a83694e962052d5fe607c9e53dde2a16
BLAKE2b-256 checksum
How to use checksums
d1ab285c6c12ddb754e3a888686bdbfad30f15bfb90dd95cba738b305f9cf441
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release files / nbtools-24.8.0-py3-none-any.whl

Download URL nbtools-24.8.0-py3-none-any.whl
Size 6.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
e34a7244e3625df945ca0c847344742a980921b963af0f5ed6cfd7f1ebd66f43
BLAKE2b-256 checksum
How to use checksums
d287b5f6dffff862623e66517972df40592607317cb8243762d95644d0a0bf04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.16

Release history Release notifications | RSS feed

This release

24.8.0 This release

2 release files

24.4.0

2 release files

23.7.0

2 release files

23.4.0

2 release files

23.1.1

2 release files

21.12

2 release files

21.2

2 release files

20.9.1

2 release files

20.9

2 release files

20.7

2 release files

20.5.1

1 release file

20.5

2 release files

20.2

2 release files

20.1

2 release files

19.10

2 release files

19.9.1

2 release files

19.9

2 release files

19.8

2 release files

19.7.4

2 release files

19.7.3

2 release files

19.7

2 release files

19.5

2 release files

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page