2

IPython 是否提供用于连接内核服务器的 Javascript 客户端 API?

我查看了https://ipython.org/ipython-doc/dev/development/messaging.html,它解释了前端和内核之间的有线协议。

我有兴趣了解当前的 Web 客户端如何与内核通信,特别是我如何利用 JavaScript 从我自己的自定义 Web 客户端以编程方式创建新笔记本

谢谢

4

1 回答 1

0

https://gist.github.com/disarticulate/d06069ff3e71cf828e5329beab8cb084

在那里你可以看到一个很好的例子:

// a very basic output handling
var handle_output = function (data) {console.log(data);}

//callbacks is an object whose so special, it appears to only have been documented in
//the source code, as no only google found me a link.
//callbacks.iopub.output is used to get the data from execute
var callbacks = {
        iopub : {
             output : handle_output,
    }
}

//execute anything you want; if a string value is returned
//you can print it out and pass it to the callbacks 
//(or do other things, no idea, it's poorly documented online 
//(read the source F12->static/notebook/js/services/kernels/kernel.js)
//kernel.js/Kernel.prototype.execute 
var kernel = IPython.notebook.kernel;
kernel.execute("print(json.dumps(python_dict))",callbacks)

您可以在 /static/services/kernels/kernel.js 中看到定义

于 2017-02-23T14:38:57.467 回答