#jupyter #protocols #messaging #message-content #reply #send-message #execute-request

jupyter-protocol

Jupyter messaging structures and traits for jupyter clients and servers

2 unstable releases

new 0.2.0 Nov 14, 2024
0.1.0 Nov 14, 2024

#1 in #reply

Download history 85/week @ 2024-11-08

97 downloads per month
Used in 4 crates (3 directly)

BSD-3-Clause

87KB
2K SLoC

jupyter-protocol

This crate provides types for JupyterMessages, for use with either the native zeromq backend (currently in runtimelib) or the websocket backend (in jupyter-websocket-client).

Usage

use jupyter_protocol::{JupyterMessage, ExecuteRequest, ExecuteReply, JupyterMessageContent};

fn main() {
    let message: JupyterMessage = ExecuteRequest {
        code: "print('Hello, world!')".to_string(),
        silent: false,
        store_history: true,
        user_expressions: Default::default(),
        allow_stdin: false,
    }.into();

    socket.send(message).await?;

    while let Some(reply) = socket.recv().await? {
        match reply.content {
            JupyterMessageContent::ExecuteReply(reply) => {
                println!("Execution completed with status: {:?}", reply.status);
            }
            JupyterMessageContent::StreamContent(content) => {
                assert_eq!(content.name, "stdout");
                assert_eq!(content.text, "Hello, world!\n");
                println!("Received stdout message: {:?}", content.text);
            }
            other => {
                println!("Received other message: {:?}", other);
            }
        }
    }
}

Dependencies

~3–4.5MB
~82K SLoC