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"),
}
}
Structs§
- Clear
Output - Clear output of a single cell / output area.
- Code
Mirror Mode Object - Comm
Close - A
comm_close
message on theiopub
channel. - CommId
- Comm
Info - Comm
Info Reply - Comm
Info Request - CommMsg
- A
comm_msg
message on theiopub
channel. - Comm
Open - A
comm_open
message on theiopub
channel. - Complete
Reply - A reply containing code completion suggestions.
- Complete
Request - A request for code completion suggestions.
- Debug
Reply - Debug
Request - Display
Data - A
display_data
message on theiopub
channel. - Error
Output - An
error
message on theiopub
channel. See Error. - Execute
Input - An
execute_input
message on theiopub
channel. See Execute Input. - Execute
Reply - 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. - Execute
Request - A request for code execution.
- Execute
Result - An
execute_result
message on theiopub
channel. See Execute Result. - Execution
Count - Represents a monotonically increasing counter for tracking the number of code executions
in a Jupyter session. This count is maintained across all executions, including those in
notebook cells and via terminal
execute_request
s. - Header
- Represents a Jupyter message header.
- Help
Link - History
Reply - A reply containing execution history.
- Input
Reply - Reply to an input request.
- Input
Request - Request for input from the frontend.
- Inspect
Reply - Inspect
Request - A
inspect_request
message on theshell
channel. - Interrupt
Reply - Reply to an interrupt request.
- Interrupt
Request - Request to interrupt the kernel.
- IsComplete
Reply - IsComplete
Request - A request to check if the code is complete and ready for execution.
- Jupyter
Message - A message in the Jupyter protocol format.
- Kernel
Info Reply - A reply containing information about the kernel.
- Kernel
Info Request - A request for information about the kernel.
- Language
Info - Media
- A
Media
is a collection of data associated with different Media types. It allows for the representation of rich content that can be displayed in multiple formats. These are found in thedata
field of aDisplayData
andExecuteResult
messages/output types. - Reply
Error - Shutdown
Reply - Reply to a shutdown request.
- Shutdown
Request - Request to shut down the kernel.
- Status
- A message indicating the current status of the kernel.
- Stream
Content - A
stream
message on theiopub
channel. These are also known as “stdout” and “stderr”. - Transient
- Optional metadata for a display data to allow for updating an output.
- Unknown
Message - Unknown message types are a workaround for generically unknown messages.
- Update
Display Data - An
update_display_data
message on theiopub
channel. See Update Display Data.
Enums§
- Channel
- Represents the different channels in the Jupyter messaging protocol.
- Code
Mirror Mode - Execution
State - History
Entry - History
Request - IsComplete
Reply Status - Jupyter
Message Content - Media
Type - An enumeration representing various Media types, otherwise known as MIME (Multipurpose Internet Mail Extensions) types.
These types are used to indicate the nature of the data in a rich content message such as
DisplayData
,UpdateDisplayData
, andExecuteResult
. - Payload
- 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 - Reply
Status - All reply messages have a
status
field. - Stdio