Jupyter JS Services
Javascript client for the Jupyter services REST APIs
Note: All functions and classes using the REST API allow an ajaxOptions
parameter to configure requests.
Package Install
Prerequisites
npm install --save jupyter-js-servicesconda install notebook # notebook 4.2+ required
Source Build
Prerequisites
git clone https://github.com/jupyter/jupyter-js-services.gitcd jupyter-js-servicesnpm installnpm run buildconda install notebook # notebook 4.2+ required
Rebuild
npm run cleannpm run build
Run Tests
Follow the source build instructions first.
npm test
Build Docs
Follow the source build instructions first.
npm run docs
Navigate to docs/index.html
.
Supported Runtimes
The runtime versions which are currently known to work are listed below. Earlier versions may also work, but come with no guarantees.
- Node 0.12.7+
- IE 11+
- Firefox 32+
- Chrome 38+
Note: "requirejs" must be included in a global context for Comm targets.
This can be as a <script>
tag in the browser or by using the requirejs
package in node (npm install requirejs
and setting
global.requirejs = require('requirejs');
). See the examples
folder
for usage.
Starting the Notebook Server
Follow the package install instructions first.
The library requires a running Jupyter Notebook server, launched as:
python -m notebook --NotebookApp.allow_origin="*"
The origin can be specified directly instead of using *
if desired.
Bundling for the Browser
Follow the package install instructions first.
See examples/browser
for an example of using Webpack to bundle the library.
Note: Some browsers (such as IE11), require a polyfill for Promises. The example demonstrates the use of the polyfill.
Usage from Node.js
Follow the package install instructions first.
npm install --save xmlhttprequest ws
Override the global XMLHttpRequest
and WebSocket
(in ES6 syntax):
;; global.XMLHttpRequest = XMLHttpRequest;global.WebSocket = WebSocket;
See examples/node
for an example of using an ES5 node script.
Usage Examples
Note: This module is fully compatible with Node/Babel/ES6/ES5. The examples below are written in TypeScript using ES6 syntax. Simply omit the type declarations when using a language other than TypeScript. A translator such as Babel can be used to convert from ES6 -> ES5.
Kernel
; // The base url of the notebook server.; // Get a list of available kernels and connect to one.Kernel.listRunning.then; // Get info about the available kernels and start a new one.Kernel.getSpecs.then;
Session
; // The base url of the Jupyter server.; // Get a list of available sessions and connect to one.Session.listRunning.then; // Start a new session.; Session.startNewoptions.then;
Comm
; // The base url of the Jupyter server.; // Create a comm from the server side.//// Get info about the available kernels and connect to one.Kernel.getSpecs.then.then; // Create a comm from the client side.getKernelSpecs.then.then;
Contents
; // The base url of the Jupyter server.; ; // Create a new python file.contents.newUntitled.then; // Get the contents of a directory.contents.get'/foo/bar'.then; // Rename a file.contents.rename'/foo/bar.txt', '/foo/baz.txt'; // Save a file.contents.save'/foo/test.ipynb'; // Delete a file.contents.delete'/foo/bar.txt'; // Copy a file.contents.copy'/foo/bar.txt', '/baz'.then; // Create a checkpoint.contents.createCheckpoint'/foo/bar.ipynb'.then; // List checkpoints for a file.contents.listCheckpoints'/foo/bar.txt'.then;
Configuration
; // The base url of the Jupyter server.; ConfigSection.create.then;
Terminals
; // Create a named terminal session and send some data.TerminalSession.open.then;