Git Product home page Git Product logo

enchannel-notebook-backend's Introduction

[WIP] enchannel-notebook-backend

enchannel version

๐Ÿ““ An enchannel backend that lets you connect to a Jupyter notebook server.

Installation

npm install enchannel-notebook-backend

Usage

Enchannel-notebook-backend provides an API for spawning, disconnecting, and shutting down remote kernels in addition to implementing the enchannel spec. A typical use would be to spawn a kernel, connect to the kernel and communicate using enchannel and Jupyter message specs, disconnect from the kernel, and optionally shut it down.

The act of connecting and disconnecting is deliberately separate to the act of spawning and shutting down a kernel. This allows one to spawn a kernel, start some compute on it, disconnect and reconnect at a later time, and shutdown the kernel when appropriate.

To use the enchannel-notebook-backend, you must have access to a running Jupyter notebook server. This library requires the Jupyter notebook server to be launched with an explicit origin. If you want to listen to all connections, launch the notebook server like so:

python -m notebook --NotebookApp.allow_origin="*"

connectionOptions

The connectionOptions object is used in almost every method described below. It's analogous to the endpoint used in enchannel-socketio-backend. A connectionOptions object looks like the following:

const connectionOptions = {
  baseUrl: 'http://localhost:8888',
  wsUrl: 'ws://localhost:8888',
};

Where baseUrl is the base URL of the notebook server
and wsUrl is the websocket URL of the notebook server.

spawn

Spawns a remote kernel by name. Takes two arguments:

  • connectionOptions, object - connections object, see above
  • kernelName, string - name of the kernel to spawn

Returns a promise with the kernel id, string.

spawn(connectionOptions, kernelName)

Usage example

const enchannelBackend = require('enchannel-notebook-backend');
enchannelBackend.spawn(connectionOptions, 'python3').then(id => {
  console.log('spawned', id);
}).catch(err => {
  console.error('Could not spawn the kernel', err);
});

connect

Connects to a remote kernel by id. Accepts two arguments:

  • connectionOptions, object - connections object, see above
  • kernelId, string - id of the kernel to connect to

Returns a promise for an enchannel spec channels object

connect(connectionOptions, kernelId)

Usage example

enchannelBackend.connect(connectionOptions, id).then(channels => {
  console.log('connected', channels);
}).catch(err => {
  console.error('Could not connect to the kernel', err);
});

For API usage of the enchannel channels object, refer to the enchannel spec README.

shutdown

Shuts down a remote kernel by id. Accepts two arguments:

  • connectionOptions, object - connections object, see above
  • kernelId, string - id of the kernel to shutdown

Returns a promise which resolves when the shutdown is complete.

shutdown(connectionOptions, kernelId)

Usage example

enchannelBackend.shutdown(connectionOptions, id).then(() => {
  console.log('shutdown');
}).catch(err => {
  console.error('Could not shutdown the kernel', err);
});

disconnect

Disconnects from a kernel by closing the channels. Accepts one argument, the enchannel channels object.

Returns promise which resolves on success.

disconnect(channels)

Usage example

enchannelBackend.disconnect(channels).then(() => {
  console.log('disconnected');
}).catch(err => {
  console.error('Could not close the channels', err);
});

Development

To develop against enchannel-notebook-backend, first clone the repo then from within the cloned folder run:

npm install
npm link

Before opening a pull request, please run the unit tests locally:

npm test

You can also verify that the code works by hand by opening the test.html file in your web browser and following the promps.

enchannel-notebook-backend's People

Contributors

captainsafia avatar jdfreder avatar rgbkrk avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

enchannel-notebook-backend's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.