Expand description
Defines the core message types and structures for the Jupyter messaging protocol.
This module provides implementations for all message types specified in the Jupyter Client documentation, including execute requests/replies, completion, inspection, and more.
§Overview
The Jupyter messaging protocol is a set of JSON-based message types used to communicate between Jupyter clients and kernels. This module provides Rust types and utilities to work with these messages in a type-safe manner.
§Main Types
JupyterMessage
: The top-level message structure, representing a complete Jupyter message.JupyterMessageContent
: An enum representing all possible message content types.- Various request and reply structures for specific message types (e.g.,
ExecuteRequest
,KernelInfoReply
).
§Examples
§Creating an Execute Request
use jupyter_protocol::{ExecuteRequest, JupyterMessage};
// Create a new execute request with the code to be executed
let execute_request = ExecuteRequest::new("print('Hello, world!')".to_string());
// Convert the request into a JupyterMessage
let message: JupyterMessage = execute_request.into();
§Handling a Received Message
use jupyter_protocol::{JupyterMessage, JupyterMessageContent};
fn handle_message(msg: JupyterMessage) {
match msg.content {
JupyterMessageContent::ExecuteRequest(req) => {
println!("Received execute request with code: {}", req.code);
},
JupyterMessageContent::KernelInfoRequest(_) => {
println!("Received kernel info request");
},
_ => println!("Received other message type"),
}
}
Re-exports§
pub use crate::media::Media;
pub use crate::media::MediaType;
pub use crate::ExecutionCount;
Structs§
- Clear output of a single cell / output area.
- A
comm_close
message on theiopub
channel. - A
comm_msg
message on theiopub
channel. - A
comm_open
message on theiopub
channel. - A reply containing code completion suggestions.
- A request for code completion suggestions.
- A
display_data
message on theiopub
channel. - A reply to an execute request. This is not the output of execution, as this is the reply over the
shell
socket. Any number of outputs can be emitted asStreamContent
,DisplayData
,UpdateDisplayData
,ExecuteResult
, andErrorOutput
. This message is used to communicate the status of the execution request, the execution count, and any user expressions that were requested. - A request for code execution.
- Represents a Jupyter message header.
- A reply containing execution history.
- Reply to an input request.
- Request for input from the frontend.
- A
inspect_request
message on theshell
channel. - Reply to an interrupt request.
- Request to interrupt the kernel.
- A request to check if the code is complete and ready for execution.
- A message in the Jupyter protocol format.
- A reply containing information about the kernel.
- A request for information about the kernel.
- Reply to a shutdown request.
- Request to shut down the kernel.
- A message indicating the current status of the kernel.
- A
stream
message on theiopub
channel. These are also known as “stdout” and “stderr”. - Optional metadata for a display data to allow for updating an output.
- Unknown message types are a workaround for generically unknown messages.
Enums§
- Represents the different channels in the Jupyter messaging protocol.
- Payloads are a way to trigger frontend actions from the kernel. They are stated as deprecated, however they are in regular use via
?
in IPython - All reply messages have a
status
field.