Module messaging

Source
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

§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§

ClearOutput
Clear output of a single cell / output area.
CodeMirrorModeObject
CommClose
A comm_close message on the iopub channel.
CommId
CommInfo
CommInfoReply
CommInfoRequest
CommMsg
A comm_msg message on the iopub channel.
CommOpen
A comm_open message on the iopub channel.
CompleteReply
A reply containing code completion suggestions.
CompleteRequest
A request for code completion suggestions.
DebugReply
DebugRequest
DisplayData
A display_data message on the iopub channel.
ErrorOutput
An error message on the iopub channel. See Error.
ExecuteInput
An execute_input message on the iopub channel. See Execute Input.
ExecuteReply
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 as StreamContent, DisplayData, UpdateDisplayData, ExecuteResult, and ErrorOutput. This message is used to communicate the status of the execution request, the execution count, and any user expressions that were requested.
ExecuteRequest
A request for code execution.
ExecuteResult
An execute_result message on the iopub channel. See Execute Result.
ExecutionCount
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_requests.
Header
Represents a Jupyter message header.
HelpLink
HistoryReply
A reply containing execution history.
InputReply
Reply to an input request.
InputRequest
Request for input from the frontend.
InspectReply
InspectRequest
A inspect_request message on the shell channel.
InterruptReply
Reply to an interrupt request.
InterruptRequest
Request to interrupt the kernel.
IsCompleteReply
IsCompleteRequest
A request to check if the code is complete and ready for execution.
JupyterMessage
A message in the Jupyter protocol format.
KernelInfoReply
A reply containing information about the kernel.
KernelInfoRequest
A request for information about the kernel.
LanguageInfo
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 the data field of a DisplayData and ExecuteResult messages/output types.
ReplyError
ShutdownReply
Reply to a shutdown request.
ShutdownRequest
Request to shut down the kernel.
Status
A message indicating the current status of the kernel.
StreamContent
A stream message on the iopub channel. These are also known as “stdout” and “stderr”.
Transient
Optional metadata for a display data to allow for updating an output.
UnknownMessage
Unknown message types are a workaround for generically unknown messages.
UpdateDisplayData
An update_display_data message on the iopub channel. See Update Display Data.

Enums§

Channel
Represents the different channels in the Jupyter messaging protocol.
CodeMirrorMode
ExecutionState
HistoryEntry
HistoryRequest
IsCompleteReplyStatus
JupyterMessageContent
MediaType
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, and ExecuteResult.
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
ReplyStatus
All reply messages have a status field.
Stdio