Skip to main content

Arbitrary python commands for notebooks in JupyterLab

Project description

jupyterlab_commands

Support for arbitrary python commands in the command palette.

Build Status codecov PyPI PyPI npm

About

This code lets you inject arbitrary commands into the JLab frontend. There are a variety of reasons why one might want to execute python commands outside of a notebook and a console:

  • a predefined NBConvert function that you dont want included in the converted result
  • interacting with VCS without including that interaction in the notebook
  • etc...

Installation

pip install jupyterlab_commands
jupyter labextension install jupyterlab_commands
jupyter serverextension enable --py jupyterlab_commands

Example

jupyter_notebook_config.py

def convertMe(request, *args, **kwargs):
    import subprocess, tornado, os, os.path, json
    data = json.loads(tornado.escape.json_decode(request.body))
    path = os.path.join(os.getcwd(), data['path'])
    subprocess.run(["jupyter", "nbconvert", path, '--template', '/Users/theocean154/.jupyter/test.tpl', '--to', 'html'])
    return {'body': 'ok'}

c.JupyterLabCommands.commands = {'sample_command': convertMe}

command palette

terminal log

No Code

Moved to jupyterlab_nbconvert_nocode

Install

pip install jupyterlab_commands
jupyter labextension install jupyterlab_commands
jupyter serverextension enable --py jupyterlab_commands

Adding commands

install the server extension, and add the following to jupyter_notebook_config.py

c.JupyterLabCommands.commands = {'command display name': python_function, ...}

Project details


Download files

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

Files for jupyterlab-commands, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size jupyterlab_commands-0.3.0-py2.py3-none-any.whl (12.4 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size jupyterlab_commands-0.3.0.tar.gz (214.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page