juno

package module
v0.0.0-...-7a9b1ca Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 8, 2024 License: BSD-3-Clause Imports: 10 Imported by: 0

README

juno

Go library for interacting with the Jupyter Messaging Protocol.

package main

import (
	"log"
	"os"

	"github.com/rgbkrk/juno"
	"github.com/zeromq/goczmq"
)

func main() {
	if len(os.Args) < 2 {
		log.Fatal("Please provide a path to a kernel runtime")
	}

	pathToKernelRuntime := os.Args[1]

	connInfo, err := juno.NewConnectionInfo(pathToKernelRuntime)

	if err != nil {
		log.Fatal(err)
	}

	// Create an iopub socket that provides go channels
	ioConnection := connInfo.IOPubConnectionString()
	iopub := goczmq.NewSubChanneler(ioConnection, "")
	defer iopub.Destroy()

	// Listen for messages... forever!
	for {
		select {
		case wireMessage := <-iopub.RecvChan:
			var message juno.Message
			err := message.ParseWireProtocol(wireMessage, connInfo)
			// Do something with the message

			if err != nil {
				// Handle the error
				log.Println("Error parsing message: ", err)
				continue
			}

			log.Println("Message: ", message)

		}
	}
}

Documentation

Overview

Package juno implements the messaging spec of the Jupyter Messaging Protocol, just for you. http://jupyter-client.readthedocs.org/en/latest/messaging.html

Index

Constants

View Source
const DELIMITER = "<IDS|MSG>"

DELIMITER denotes the Jupyter multipart message

Variables

This section is empty.

Functions

func NewUUID

func NewUUID() string

NewUUID creates a new UUID

Types

type ConnectionInfo

type ConnectionInfo struct {
	IOPubPort       int    `json:"iopub_port"`
	StdinPort       int    `json:"stdin_port"`
	IP              string `json:"ip"`
	Transport       string `json:"transport"`
	HBPort          int    `json:"hb_port"`
	SignatureScheme string `json:"signature_scheme"`
	ShellPort       int    `json:"shell_port"`
	ControlPort     int    `json:"control_port"`
	Key             string `json:"key"`
}

ConnectionInfo represents the runtime connection data used by Jupyter kernels

func NewConnectionInfo

func NewConnectionInfo(filename string) (ConnectionInfo, error)

NewConnectionInfo reads in a connection file and creates a ConnectionInfo struct

func (*ConnectionInfo) ConnectionString

func (connInfo *ConnectionInfo) ConnectionString(port int) string

ConnectionString forms the string for zmq libraries to connect

func (*ConnectionInfo) ControlConnectionString

func (connInfo *ConnectionInfo) ControlConnectionString() string

func (*ConnectionInfo) HBConnectionString

func (connInfo *ConnectionInfo) HBConnectionString() string

func (*ConnectionInfo) IOPubConnectionString

func (connInfo *ConnectionInfo) IOPubConnectionString() string

IOPubConnectionString forms the connection string for the IOPub socket This is simply a wrapper around ConnectionString with the IOPub port

func (*ConnectionInfo) ShellConnectionString

func (connInfo *ConnectionInfo) ShellConnectionString() string

func (*ConnectionInfo) StdinConnectionString

func (connInfo *ConnectionInfo) StdinConnectionString() string

type Message

type Message struct {
	Header       MessageHeader          `json:"header"`
	ParentHeader MessageHeader          `json:"parent_header"`
	Metadata     map[string]interface{} `json:"metadata"`
	Content      map[string]interface{} `json:"content"`
}

Message is a generic Jupyter message (not a wire message) http://jupyter-client.readthedocs.org/en/latest/messaging.html#general-message-format

func ExecuteRequest

func ExecuteRequest(code string) Message

ExecuteRequest sends an execution request to the Jupyter kernel

func NewMessage

func NewMessage(msgType string) Message

NewMessage creates a new Jupyter message

func (*Message) ParseWireProtocol

func (m *Message) ParseWireProtocol(wireMessage [][]byte, connInfo ConnectionInfo) (err error)

ParseWireProtocol fills a Message with all the juicy Jupyter bits

type MessageHeader

type MessageHeader struct {
	MessageID   string `json:"msg_id"`
	Username    string `json:"username"`
	Session     string `json:"session"`
	MessageType string `json:"msg_type"`
	Version     string `json:"version"`
}

MessageHeader is a Jupyter message header http://jupyter-client.readthedocs.org/en/latest/messaging.html

type MimeBundle

type MimeBundle map[string]string

MimeBundle is a collection of `mimetypes -> data` Example:

'text/html' -> '<h1>Hey!</h1>'
'image/png' -> 'R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL