Zsailer / jupyter_server_extension

Jupyter server extensions as applications [experimental]

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

jupyter_server_extension

Launch Jupyter server extensions as Jupyter applications.

This is an experimental library for making applications out of Jupyter server extensions.

How to write an extension

The following describes the pattern for writing a jupyter server extension that also works as a standalone application.

  1. Subclass the ExtensionHandler to handler API requests. This handler points the static_url to namespaced endpoints under the static url pattern.
from jupyter_server_extension.handler import JupyterExtensionHandler

class MyExtensionHandler(ExtensionHandler):

    def get(self):
        self.render_template("index.html")
  1. Subclass the ExtensionApp and add handlers.
from traitlets import Unicode
from jupyter_server_extension.application import ExtensionApp

class MyExtensionApp(ExtensionApp):

    name = Unicode("my_extension")

    static_paths = List(
        Unicode("/path/to/static/dir/"),
        help="""List of places to file static served files."""
    )

        
    def initialize_handlers(self):
        self.handlers = []
        self.handlers.append(
            (r'/myextension', MyExtensionHandler)
        )

# `launch_instance` method offers an entry point to start the server and application. 
main = MyExtensionApp.launch_instance

# `load_jupyter_server_extension` method allows extension to be appended to already running server. 
load_jupyter_server_extension = MyExtensionApp.load_jupyter_server_extension

About

Jupyter server extensions as applications [experimental]


Languages

Language:Python 100.0%