Browser communication with Jupyter Python kernel

1,339 views
Skip to first unread message

Christopher Brooks

unread,
Nov 11, 2016, 7:19:09 PM11/11/16
to Project Jupyter
Hi,

I'm trying to do a bit of rapid prototyping of a jupyter javascript extension which invokes services against a python kernel. The docs take some serious time, but what I've groked is that there are a set of REST-based services which I call, but it seems like these services do not allow me to push code to the kernel, just identify which kernels and sessions are available. It seems instead that once I have identified a kernel, I can use this wire protocol for interaction with the kernel. However, I'm unclear which endpoint to push messages to and feel like there must be a browser-based Javascript library available for this purpose. COMMs caught my eye, but again, it seems like it should be more straight forward to push some python strings to a kernel and observe the results. The JupyterLab Services looked promising, but it's all Node.jsified, which makes me think this is the wrong tree to bark down.

Maybe someone could give me a gentle nudge in the right direction?

(I sort of expected something as trivial as an IPython.Notebook.execute("somecode")....)

Regards,

Chris

MinRK

unread,
Nov 12, 2016, 4:39:06 PM11/12/16
to Project Jupyter

JupyterLab services is for use in the browser, that’s what JupyterLab uses to talk to these APIs. If you are already in the existing pre-Lab notebook and want to run code on the current kernel, the API you are after is:

Jupyter.notebook.kernel.execute("some code", callbacks)

-MinRK


--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/4823f311-80a5-4597-abbd-fc86b17bf0ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher Brooks

unread,
Nov 12, 2016, 5:39:12 PM11/12/16
to jup...@googlegroups.com

Wonderful, thanks very much MinRK. Is callbacks just a function which takes a single parameter, or are there docs on this api which I have overlooked?

Chris


--
You received this message because you are subscribed to a topic in the Google Groups "Project Jupyter" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jupyter/FJwiVIOxUXc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jupyter+unsubscribe@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

MinRK

unread,
Nov 18, 2016, 7:52:23 AM11/18/16
to Project Jupyter

On Sat, Nov 12, 2016 at 11:39 PM, Christopher Brooks <broo...@umich.edu> wrote:

Wonderful, thanks very much MinRK. Is callbacks just a function which takes a single parameter, or are there docs on this api which I have overlooked?

callbacks is a structure for different types of callbacks. Its shape is described here.

-Min

Doug Blank

unread,
Nov 18, 2016, 8:05:47 AM11/18/16
to Project Jupyter
On Friday, November 18, 2016 at 7:52:23 AM UTC-5, Min RK wrote:

On Sat, Nov 12, 2016 at 11:39 PM, Christopher Brooks <broo...@umich.edu> wrote:

Wonderful, thanks very much MinRK. Is callbacks just a function which takes a single parameter, or are there docs on this api which I have overlooked?

callbacks is a structure for different types of callbacks. Its shape is described here.


I'm working with some code that calls this as well. Are the standard callbacks (for print, error handling, display, etc) available to plugin in here? It would be handy to have the standard callbacks available, or to be able to slightly alter/replace particular ones (eg, dispay). 

-Doug

 

-Min

Chris


On Nov 12, 2016 4:39 PM, "MinRK" <benja...@gmail.com> wrote:

JupyterLab services is for use in the browser, that’s what JupyterLab uses to talk to these APIs. If you are already in the existing pre-Lab notebook and want to run code on the current kernel, the API you are after is:

Jupyter.notebook.kernel.execute("some code", callbacks)

-MinRK

On Fri, Nov 11, 2016 at 4:19 PM, Christopher Brooks <broo...@umich.edu> wrote:
Hi,

I'm trying to do a bit of rapid prototyping of a jupyter javascript extension which invokes services against a python kernel. The docs take some serious time, but what I've groked is that there are a set of REST-based services which I call, but it seems like these services do not allow me to push code to the kernel, just identify which kernels and sessions are available. It seems instead that once I have identified a kernel, I can use this wire protocol for interaction with the kernel. However, I'm unclear which endpoint to push messages to and feel like there must be a browser-based Javascript library available for this purpose. COMMs caught my eye, but again, it seems like it should be more straight forward to push some python strings to a kernel and observe the results. The JupyterLab Services looked promising, but it's all Node.jsified, which makes me think this is the wrong tree to bark down.

Maybe someone could give me a gentle nudge in the right direction?

(I sort of expected something as trivial as an IPython.Notebook.execute("somecode")....)

Regards,

Chris

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/4823f311-80a5-4597-abbd-fc86b17bf0ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to a topic in the Google Groups "Project Jupyter" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/jupyter/FJwiVIOxUXc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to jupyter+u...@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+u...@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

MinRK

unread,
Nov 18, 2016, 8:25:29 AM11/18/16
to Project Jupyter

On Fri, Nov 18, 2016 at 2:05 PM, Doug Blank <doug....@gmail.com> wrote:

On Friday, November 18, 2016 at 7:52:23 AM UTC-5, Min RK wrote:

On Sat, Nov 12, 2016 at 11:39 PM, Christopher Brooks <broo...@umich.edu> wrote:

Wonderful, thanks very much MinRK. Is callbacks just a function which takes a single parameter, or are there docs on this api which I have overlooked?

callbacks is a structure for different types of callbacks. Its shape is described here.


I'm working with some code that calls this as well. Are the standard callbacks (for print, error handling, display, etc) available to plugin in here? It would be handy to have the standard callbacks available, or to be able to slightly alter/replace particular ones (eg, dispay). 

There are separate callbacks for each cell (this is how output is routed to different cells for different requests). You can get the default callbacks for a given code cell with cell.get_callbacks().

-MinRK

To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.

To post to this group, send email to jup...@googlegroups.com.

Doug Blank

unread,
Nov 18, 2016, 9:01:34 AM11/18/16
to Project Jupyter

Perfect!

-Doug

Doug Blank

unread,
Jan 16, 2017, 6:15:47 PM1/16/17
to jup...@googlegroups.com
On Sat, Nov 12, 2016 at 4:38 PM, MinRK <benja...@gmail.com> wrote:

JupyterLab services is for use in the browser, that’s what JupyterLab uses to talk to these APIs. If you are already in the existing pre-Lab notebook and want to run code on the current kernel, the API you are after is:

Jupyter.notebook.kernel.execute("some code", callbacks)

-MinRK

This is a very handy indeed:

cell = Jupyter.notebook.get_cell(0) ; // cell number
Jupyter.notebook.kernel.execute("%python print(42)", cell.get_callbacks())

But what if you want to use Javascript to generate the message (rather than the kernel) to print to the cell? Is there an easy method to do that?

-Doug

 

On Fri, Nov 11, 2016 at 4:19 PM, Christopher Brooks <broo...@umich.edu> wrote:
Hi,

I'm trying to do a bit of rapid prototyping of a jupyter javascript extension which invokes services against a python kernel. The docs take some serious time, but what I've groked is that there are a set of REST-based services which I call, but it seems like these services do not allow me to push code to the kernel, just identify which kernels and sessions are available. It seems instead that once I have identified a kernel, I can use this wire protocol for interaction with the kernel. However, I'm unclear which endpoint to push messages to and feel like there must be a browser-based Javascript library available for this purpose. COMMs caught my eye, but again, it seems like it should be more straight forward to push some python strings to a kernel and observe the results. The JupyterLab Services looked promising, but it's all Node.jsified, which makes me think this is the wrong tree to bark down.

Maybe someone could give me a gentle nudge in the right direction?

(I sort of expected something as trivial as an IPython.Notebook.execute("somecode")....)

Regards,

Chris

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jupyter/4823f311-80a5-4597-abbd-fc86b17bf0ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Project Jupyter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jupyter+unsubscribe@googlegroups.com.
To post to this group, send email to jup...@googlegroups.com.

Doug Blank

unread,
Jan 16, 2017, 8:23:58 PM1/16/17
to jup...@googlegroups.com
I have some working code:

function(message) {
    Jupyter.notebook.get_cell(0).get_callbacks().iopub.output({header: {"msg_type": "stream"},
      content: {text: message + "\n",
name: "stdout"}})
};

Is there anything better?

-Doug
Reply all
Reply to author
Forward
0 new messages