timkpaine / jupyterlab_commands

Add arbitrary python commands to the jupyterlab command palette

Home Page:https://jupyterlab-commands.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jupyterlab_commands

Support for arbitrary python commands in the command palette.

Build Status codecov PyPI PyPI npm Binder

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_lab_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, '--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, ...}

About

Add arbitrary python commands to the jupyterlab command palette

https://jupyterlab-commands.readthedocs.io

License:Apache License 2.0


Languages

Language:JavaScript 50.1%Language:Python 25.1%Language:Makefile 22.2%Language:Shell 2.6%