nbformat

package
v0.0.113 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package nbformat provides utilities to read and parse Jupyter Notebook (nbformat) files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	CellType string                 `json:"cell_type"`
	Source   string                 `json:"source"` // Could be []string, but we always convert it to a single string
	Metadata map[string]interface{} `json:"metadata"`
	Outputs  []Output               `json:"outputs,omitempty"`
}

Cell represents a single cell within a Jupyter Notebook.

func (*Cell) UnmarshalJSON added in v0.0.113

func (c *Cell) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshals a Cell to ensure Source is always a single string.

type KernelSpec added in v0.0.113

type KernelSpec struct {
	Name        string `json:"name"`
	DisplayName string `json:"display_name"`
}

KernelSpec represents the kernel specification in the metadata.

type LanguageInfo added in v0.0.113

type LanguageInfo struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

LanguageInfo represents the language information in the metadata.

type Metadata added in v0.0.113

type Metadata struct {
	KernelSpec   KernelSpec   `json:"kernelspec"`
	LanguageInfo LanguageInfo `json:"language_info"`
}

Metadata represents the metadata of a Jupyter Notebook.

type Notebook

type Notebook struct {
	Metadata      Metadata `json:"metadata"`
	Nbformat      int      `json:"nbformat"`
	NbformatMinor int      `json:"nbformat_minor"`
	Cells         []Cell   `json:"cells"`
}

Notebook represents a Jupyter Notebook containing multiple cells.

func ReadNBFormat

func ReadNBFormat(r io.Reader) (*Notebook, error)

ReadNBFormat reads and parses a Jupyter Notebook from the given io.Reader. It returns a pointer to the Notebook struct containing the parsed content. If there is an error during reading or parsing, it returns an error.

type Output

type Output struct {
	OutputType string                 `json:"output_type"`
	Text       string                 `json:"text,omitempty"` // Could be []string, but we always convert it to a single string
	Data       map[string]interface{} `json:"data,omitempty"`
	Metadata   map[string]interface{} `json:"metadata,omitempty"`
	ErrorName  string                 `json:"ename,omitempty"`
	ErrorValue string                 `json:"evalue,omitempty"`
	Traceback  []string               `json:"traceback,omitempty"`
}

Output represents the output of a cell in a Jupyter Notebook.

func (*Output) UnmarshalJSON added in v0.0.113

func (o *Output) UnmarshalJSON(data []byte) error

UnmarshalJSON custom unmarshals an Output to ensure Text is always a single string.

Jump to

Keyboard shortcuts

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