#jupyter #websocket-client #server #reader #kernel #launch

jupyter-websocket-client

Connect to Jupyter Servers over WebSockets

11 releases (breaking)

0.9.0 Jan 9, 2025
0.8.0 Dec 2, 2024
0.7.0 Dec 2, 2024
0.6.0 Nov 28, 2024

#56 in WebSocket

Download history 186/week @ 2024-10-30 16/week @ 2024-11-06 738/week @ 2024-11-13 2695/week @ 2024-11-20 2959/week @ 2024-11-27 2666/week @ 2024-12-04 2347/week @ 2024-12-11 1833/week @ 2024-12-18 1287/week @ 2024-12-25 2474/week @ 2025-01-01 3446/week @ 2025-01-08 2234/week @ 2025-01-15 2301/week @ 2025-01-22 2165/week @ 2025-01-29 2374/week @ 2025-02-05 2290/week @ 2025-02-12

9,454 downloads per month

BSD-3-Clause

135KB
2.5K SLoC

jupyter-websocket-client crate

Note: This crate does not support tokio at this time.

Usage

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(())
}

Dependencies

~17–28MB
~529K SLoC