Options
All
  • Public
  • Public/Protected
  • All
Menu

Package messaging

@nteract/messaging

This package contains type definitions and helper functions for interacting with the Jupyter Messaging Protocol. These functions can be used to create different types of request and response messages.

Installation

$ yarn add @nteract/messaging
$ npm install --save @nteract/messaging

Usage

The example below shows how we can use the createMessage function in this package to create an inspect_request Jupyter message.

import { createMessage } from "@nteract/messaging";

const message = createMessage("inspect_request", { code: "string.for", cursor_pos: 10, detail_level: 1 });

Documentation

You can view the reference documentation for @nteract/messaging in the package docs.

Support

If you experience an issue while using this package or have a feature request, please file an issue on the issue board and add the pkg:messaging label.

License

BSD-3-Clause

Index

Type aliases

Channel

Channel: "shell" | "iopub" | "stdin"

Channels

Channels: Subject<JupyterMessage>

ExecuteRequest

ExecuteRequest: JupyterMessage<"execute_request", ExecuteMessageContent>

MessageType

MessageType: "execute_request" | "inspect_request" | "inspect_reply" | "kernel_info_request" | "kernel_info_reply" | "complete_request" | "history_request" | "history_reply" | "is_complete_request" | "comm_info_request" | "comm_info_reply" | "shutdown_request" | "shutdown_reply" | "shell" | "display_data" | "stream" | "update_display_data" | "execute_input" | "execute_result" | "error" | "status" | "clear_output" | "iopub" | "input_request" | "input_reply" | "stdin" | "comm_open" | "comm_msg" | "comm_close" | "complete_reply" | "is_complete_reply" | "execute_reply" | "interrupt_request" | "interrupt_reply"

UpdateDisplayData

UpdateDisplayData: JupyterMessage<"update_display_data", UpdateDisplayDataContent>

Variables

Const REQUIRED_NUMBER_OF_MESSAGE_FRAMES

REQUIRED_NUMBER_OF_MESSAGE_FRAMES: 5 = 5

Const WIRE_PROTOCOL_DELIMITER

WIRE_PROTOCOL_DELIMITER: "<IDS|MSG>" = "<IDS|MSG>"

Const crypt

crypt: any = require("crypto")

Functions

childOf

  • operator for getting all messages that declare their parent header as parentMessage's header.

    Parameters

    • parentMessage: JupyterMessage

      The parent message whose children we should fetch

    Returns function

    A function that takes an Observable of kernel messages and returns messages that are children of parentMessage.

clearOutput

convertOutputMessageToNotebookFormat

createCommCloseMessage

  • createCommCloseMessage(parent_header: any, comm_id: string, data?: any): JupyterMessage<"comm_close", any>
  • creates a comm close message for sending to a kernel

    Parameters

    • parent_header: any

      header from a parent jupyter message

    • comm_id: string

      unique identifier for the comm

    • Default value data: any = {}

      any data to send for the comm

    Returns JupyterMessage<"comm_close", any>

    jupyter message for comm_msg

createCommMessage

  • createCommMessage(comm_id: string, data?: any, buffers?: Uint8Array): JupyterMessage<"comm_msg", any>
  • creates a comm message for sending to a kernel

    Parameters

    • comm_id: string

      unique identifier for the comm

    • Default value data: any = {}

      any data to send for the comm

    • Default value buffers: Uint8Array = new Uint8Array([])

      arbitrary binary data to send on the comm

    Returns JupyterMessage<"comm_msg", any>

    jupyter message for comm_msg

createCommOpenMessage

  • createCommOpenMessage(comm_id: string, target_name: string, data?: any, target_module: string): JupyterMessage<"comm_open", any>
  • creates a comm open message

    Parameters

    • comm_id: string

      uuid

    • target_name: string

      comm handler

    • Default value data: any = {}

      up to the target handler

    • target_module: string

      used to select a module that is responsible for handling the target_name

    Returns JupyterMessage<"comm_open", any>

    Message ready to send on the shell channel

createExecuteRequest

createHeader

createMessage

decode

  • decode(messageFrames: Array<Buffer>, key?: string, _scheme?: string): RawJupyterMessage
  • Convert raw message frames from a Jupyter ZeroMQ connection to the object based JupyterMessage format

    Parameters

    • messageFrames: Array<Buffer>

      individual components of a message

    • Optional key: string

      HMAC key for frames 2+

    • Default value _scheme: string = "sha256"

      only sha256 is supported at the moment

    Returns RawJupyterMessage

displayData

  • displayData<C, T>(content: C, msg_type: T): JupyterMessage<T, C>
  • displayData<C>(content: C, msg_type?: undefined): JupyterMessage<"display_data", C>

encode

  • encode(_message: Partial<RawJupyterMessage>, key?: string, _scheme?: string): Buffer[]

error

executeInput

executeReply

executeRequest

  • An execute request creator

    executeRequest('print("hey")', { 'silent': true }) { header: { msg_id: 'f344cc6b-4308-4405-a8e8-a166b0345579', date: 2017-10-23T22:33:39.970Z, version: '5.0', msg_type: 'execute_request', username: 'kyle', session: '123' }, metadata: {}, parent_header: {}, content: { code: 'print("hey")', silent: false, store_history: true, user_expressions: {}, allow_stdin: true, stop_on_error: false } }

    Parameters

    • Default value code: string = ""

      The code to execute

    • Default value options: object = {}

      The options for the execute request

      • Optional allow_stdin?: boolean
      • Optional silent?: boolean
      • Optional stop_on_error?: boolean
      • Optional store_history?: boolean
      • Optional user_expressions?: object

    Returns ExecuteRequest

    A complete execute_request message

executeResult

  • executeResult(content: object): JupyterMessage<"execute_result", object>

Const executionCounts

  • executionCounts(): (Anonymous function)

identifyHMACScheme

  • identifyHMACScheme(_scheme: string): string
  • Convert from Pythonic HMAC scheme string to node.js compatible name.

    Only support sha256 at the moment, which is all Jupyter uses nowadays anyhow.

    Parameters

    • _scheme: string

      Examples: "hmac-sha256", "sha256"

    Returns string

initializeMessage

inputReply

Const inputRequests

  • inputRequests(): (Anonymous function)

kernelInfoRequest

Const kernelStatuses

  • kernelStatuses(): (Anonymous function)

message

  • Returns a fully-formatted kernel message.

    Type parameters

    Parameters

    • header: object

      An object containing the message type and session information

      • msg_type: MT
      • Optional session?: string
      • Optional username?: string
    • Default value content: object = {}

      The message type-specific contents to send in the kernel message

    Returns JupyterMessage<MT>

    The fully-formatted kernel message

Const ofMessageType

  • ofMessageType<T>(...messageTypes: Array<T | [T]>): function

Const outputs

  • outputs(): (Anonymous function)
  • Convert raw Jupyter messages that are output messages into nbformat style outputs

    o$ = iopub$.pipe( childOf(originalMessage), outputs() )

    Returns (Anonymous function)

Const payloads

  • payloads(): (Anonymous function)
  • Get all the payload message content from an observable of jupyter messages

    p$ = shell$.pipe( childOf(originalMessage), payloads() )

    Returns (Anonymous function)

shutdownRequest

  • shutdownRequest(content?: object): JupyterMessage<"shutdown_request", object>
  • Creates a message to request the shutdown of a kernel.

    Parameters

    • Default value content: object = { restart: false }

      An options object containing whether or not to restart the kernel

      • Optional restart?: boolean

    Returns JupyterMessage<"shutdown_request", object>

    A shutdown_request message

status

  • status(execution_state: "busy" | "idle" | "starting"): JupyterMessage<"status", any>

stream

toJSON

  • toJSON(value: any): any

updateDisplayData

Const updatedOutputs

  • updatedOutputs(): (Anonymous function)

whichChannel

  • Returns which channel, iopub or stdin or shell, to send a kernel message through.

    Parameters

    • Optional messageType: MessageType

      The message type to fetch a channel for

    Returns Channel

    The channel to send a kernel message through

withCommId

  • withCommId(comm_id: string): function
  • operator for getting all messages with the given comm id

    Parameters

    • comm_id: string

      The comm id that we are filtering by

    Returns function

    A function that takes an Observable of kernel messages and returns messages that have the given comm id

Object literals

Const wireProtocol

wireProtocol: object

decode

decode: decode

encode

encode: encode

Generated using TypeDoc