Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Yet Another Node.JS Kernel for the Jupyter Notebook 👨

License

NotificationsYou must be signed in to change notification settings

3Nigma/nelu-kernelu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

80 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A modern, Promise ready, NodeJS Jupyter5.2.3 Kernel with comm and display support. This work was heavily inspired byNicolas Riesco'sIJavascript kernel and is, in some sense, a continuation of that.

Currious of what it can do? Well ...have a look.

Supported features

  • Allows plain cell results
    plain results
  • Resolves promisified values into plain results
    promise results
  • Masksundefined results
  • Permits creating and working with comms from within a cell (via Jupytercomm_create andcomm_msg)
  • Capable of handling comm messages originating from the kernel
  • Able to display custom MIME specific content (via Jupyterdisplay_create messages)
  • Can print strings (viastream messages)
  • Supports kernel restarting via the Notebook UI
  • Has error stack tracing

Installing

RequiresNodeJS v12.3+ installed on the machine that hosts the Jupyter Notebook server alongside theNeluKernelu JS kernel.

We're not (yet) on NPM so, for now, you would have to manually do agit clone followed by anpm install which not only fetches the dependencies, but also makes the kernel available to Jupyter.

If you then want to use it, just open jupyter (viajupyter notebook, for instance) and you should see it listed there.

Restricted features

Due to security considerations, the following NodeJS objects are not available to be used from within a cell:

  • global
  • process

API

Whenever a Notebook is started which targets this NodeJS kernel, a specialkernel object is created and made available on each and every code cell. This object exposes kernel functionality into cell-space.

Versioning

The running kernel version is made available viakernel.version. This exposes an object with 2 properties:

  • name - ax.y.z.w string wherex.y.z follows theJupyter Client Specs currrently supported andw is a source build number
  • code - a numeric codification ofname for easier usage. The value is actually computed asxyz000 + w wherex,y andz are thename digits andw is the current build number

Getting the running user-name

To get the current running user-name, just callkernel.userName. This is helpful to deduce the current user especially in hub-like (+ oAuth) environments.

Logging messages

can be achieved via doing akernel.print() call passing in thestring that you want shown underneath the cell like so:
kernel.print(string)If you want to get fancy, you can also work with formattable constructs the same way you would go usingutil.format. Thus, you can do things like:
kernel.print(format[, ...args])Note: By design,console.log does not have the same effect askernel.print. Using the traditionalconsole.log has the effect of logging to the system console instead of the user's notebook.

Dealing with communication channels (comms)

Opening comms

The user can currently open a Jupyter communication channel (comm, for short) in one of two ways:

  • throughkernel.commManager.newComm() which creates a new comm that has a target name ofjknb.comm and an initial data payload of{} (empty JS object)or
  • throughkernel.commManager.newCommFor() which takes in 3 parameters offering increased flexibility:
    • targetName -mandatory, the comm's target name
    • initialData -optional (defaults to{}), the comm's initial-data object payload
    • metaData -optional (defaults to{}), the comm's metadata object payloadBoth these methods yeild a newSessionKernelComm instance which can be used to both send and receive messages.

Sending data through comms

can be achieved via calls to a comm's instanceSessionKernelComm.send() method. The onlymandatory argument being the JS object that we want to be broadcasted on that comm.

Receiving data via comms

is done subscribing to the "message" event of the desiredSessionKernelComm instance like so:

wComm.on("message", ({ data }) => kernel.print(JSON.stringify(data)));

The registered message handler will receive one parameter which will always be an object with a single property,data that carries whatever payload received through that comm.

Displaying into the output cell

To display something into an output cell, you need to callkernel.display on an instance of a class that extendsJupyterDisplayableMessage in which you overwrite_toDisplay() returning whatever JS object you would like to display as a result.Here's an example:
kernel.display(JupyterDisplayableMessage)

Still needs to be done

  • Testing! The automatic kind ...
  • Handling ofcomm_close messages
  • Handlecomm_open messages originating from outside the kernel
  • Make kernel interruption work for all/most of the cases
  • Research the rest of theJupyter Widgets, document the findings inside areengineered markdown entry and provide an implementation

Contributors

  • Victor ADASCALITEI - repo owner
  • Radu MILICI

How to participate?

Contribute! PRs are more then welcomed, but bugs and/or feature requests are also fine. Every bit of effort is appreciated.

About

Yet Another Node.JS Kernel for the Jupyter Notebook 👨

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp