Is it possible to connect the IPyhton command line (I run it inside Neovim using iron.nvim) to a Jupyterhub server, using the Hub url and token e.g.: https://your-hub-url/user/your-hub-user-name/?token=your-token, similarly to what can be done in VSCode as shown here Jupyter Notebooks on the web ? Tks
I believe so. See both answers here.
Also, you’ll get IPython by connecting to a Console kernel on the remote machine. (In fact, that is why I linked to that particular first answer, because it features the ‘New Console for Kernel’ choice.)
Or even when directly using Jupyter, Console essentially equals IPython. I can guide you through seeing that in action without touching your own machine or signing up for anything or logging into anything. Go here and click the ‘launch binder
’ badge just down bellow the many other badges. A remote Jupyter session will spin up. Click the blue ‘Plus’ button and select from the Launcher page ‘Python 3 (ipykernel)’. You’ll see when the console comes up it features IPython. Here is a screenshot:
*I changed to theme to JupyterLab Dark before I took the screenshot to emphasize it is IPython console.
Other related answers & resources to look at:
- python - Connecting to a remote IPython instance - Stack Overflow
- How do I connect to a remote kernel via the Jupyter Notebook Server API? · Issue #508 · jupyter/jupyter_client · GitHub
- Jupyter Kernel Gateway — Jupyter Kernel Gateway 3.0.1 documentation
- Single-user setups for local client & remote kernel - #8 by kevin-bates
- The more standard way for those not looking to use local software to connect to the remote machine/kernel: How to run a jupyter notebook through a remote server on local machine? - Stack Overflow
Thanks for your answer. I’m not sure if I explained correctly, but I’m also struggling to understand the answers you pointed me to, so I’ll try to be more detailed.
I work with satellite imagery, and some organizations provide cloud processing via Python on their Jupyter servers, so you can run your code directly where the data is located.
For instance this server from the European Space Agency that I’m working with ATM. Once you login, you are able to obtain a Token
I can then put this token in a URL in the form https://jupyterhub.dataspace.copernicus.eu/user/my@email.com/?token=12345678 and give it to VSCode to be able to work with that remote server from inside VSCode locally:
What I’d like to achieve is, instead of connecting to the remote kernel from VSCode, to connect and interact with the remote kernel from an Ipython session running inside my local terminal emulator, similar to what can be achieved by launching jupyter console --existing kernel-a9c61cb2-4d7e-4301-b48d-d76e311f3125.json
when running a Jupyter server locally.
The end goal being being to work in the remote kernel from within my local terminal, using Neovim and the IPython console, instead of VSCode.
Ideally something like jupyter console –server ``http://jupyterhub.dataspace.coperninus.eu/user/my@email.com/?token=12345678`` --existing kernel.json
but I don’t think anything similar exists.
On the remote server, using the browser interface, I can open a terminal and get the contents of the he jpserver.json and kernel.json files inside ~/.local/share/jupyter/runtime/
. But I’m not sure what I can do with them.
I suppose there must be a way, since VSCode can do it. I had plenty of screenshots to illustrate this post, but as a new user I can only post one image and had to delete them.
It is technically possible, but the key missing piece is that jupyter console
hasn’t implemented the client side of the websocket protocol.
There are two wire protocols for talking to Jupyter kernels.
- the zmq protocol, for direct connections (the reference implementation is in
jupyter-client
). Kernels speak only this protocol, andjupyter-server
andjupyter-console
are both examples of applications that speak the client side of this protocol. - the websocket protocol, for talking to a webserver.
jupyter-server
translates the zmq protocol (as a client) to the websocket protocol (as a server). This is how web applications like JupyterLab talk to kernels, mediated byjupyter-server
as a translation layer.
In order to talk through JupyterHub auth to kernels, you need to speak the websocket protocol, because JupyterHub exposes only HTTPS. Apparently vscode does this, if it can talk to kernels via JupyterHub. Jupyter console could do this, but does not yet have a client implementation of the websocket protocol at this point, only direct connection via the zmq protocol.
jpterm is a project that aims to be a terminal client to Jupyter servers, which does support the server protocol, but appears to be highly experimental. I’m not sure how functional it is at the moment.
Or you could go wild and forward ports with jupyterhub-ssh, then jupyter-console
could actually connect to remote kernels.
Thank for the explanations and options. Definitely not as straightforward as I hoped.
jpterm is connecting to the server then crashing right away. I’m trying to figure that out.
As for jupyterhub-ssh, I don’t think I can forward any ports from within the remote server.