Crates.io | jupyter-websocket-client |
lib.rs | jupyter-websocket-client |
version | 0.8.0 |
source | src |
created_at | 2024-10-27 21:00:03.25334 |
updated_at | 2024-12-02 22:53:17.642472 |
description | Connect to Jupyter Servers over WebSockets |
homepage | |
repository | https://github.com/runtimed/runtimed |
max_upload_size | |
id | 1424962 |
size | 10,880 |
jupyter-websocket-client
crateNote: This crate does not support tokio at this time.
use jupyter_websocket_client::RemoteServer;
use jupyter_protocol::{KernelInfoRequest, JupyterMessageContent};
// Import the sink and stream extensions to allow splitting the socket into a writer and reader pair
use futures::{SinkExt as _, StreamExt as _};
pub async fn connect_kernel() -> anyhow::Result<()> {
let server = RemoteServer::from_url(
"http://127.0.0.1:8888/lab?token=f487535a46268da4a0752c0e162c873b721e33a9e6ec8390"
)?;
// You'll need to launch a kernel and get a kernel ID using your own HTTP
// request library
let kernel_id = "1057-1057-1057-1057";
let kernel_socket = server.connect_to_kernel(kernel_id).await?;
let (mut w, mut r) = kernel_socket.split();
w.send(KernelInfoRequest {}.into()).await?;
while let Some(response) = r.next().await.transpose()? {
match response.content {
JupyterMessageContent::KernelInfoReply(kernel_info_reply) => {
println!("Received kernel_info_reply");
println!("{:?}", kernel_info_reply);
break;
}
other => {
println!("Received");
println!("{:?}", other);
}
}
}
Ok(())
}