symmetryinvestments / jupyter-wire

Jupyter wire protocol implementation enabling D plugins to be jupyter kernels
Boost Software License 1.0
13 stars 4 forks source link
jupyter-kernels jupyter-wire

jupyter-wire

Build Status

An implementation of the Jupyter wire protocol in D. This depends on ZeroMQ so the relevant development library (zmq.dll, libzmq.so, ...) will have to be installed on the system for this to link.

This library was written so that any backend written in or callable by D can be a jupyter kernel. A backend must be a D type that satisfies the following compile-time interface:

import jupyter.wire.kernel: LanguageInfo, ExecutionResult;
LanguageInfo info = T.init.languageInfo;
ExecutionResult result = T.init.execute("foo");

For a backend type that doesn't require initialisation, the following code is sufficient:

struct MyBackend {
    enum languageInfo = LanguageInfo(/*...*/);
    ExecutionResult execute(in string code) {
       // ...
    }
}

import jupyter.wire.kernel: Main;
mixin Main!MyBackend;

Otherwise, initialise as necessary and call Kernel.run:

import jupyter.wire.kernel: kernel;
auto k = kernel(backend, connectionFileName);
k.run;

Examples

Windows

Set the environment variables ZMQ_DIR_32 and/or ZMQ_DIR_64 for where to find the zmq.lib when building. Remember to copy the revelant .dll to the executable path.

Text and markdown output

To return text output, use the textResult helper function:

return textResult("this is the output", Stdout("This is stdout side-effect"));

Similarly for markdown output:

return markdownResult("# This is a header");

In both cases the Stdout parameter is optional.