nbformat

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2020 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

nbformat

Golang package for manipulating IPython/Jupyter notebook .ipynb files.

Warning

Probably don't use this. This isn't v0.0.1 yet and I'm not going to bother v2-ing things until this package fits my needs.

Setup Python Test Environment

pip -m venv .env
source .env/bin/activate
pip install -r requirements.txt

Documentation

Index

Constants

View Source
const (
	CellTypeMarkdown = "markdown"
	CellTypeRaw      = "raw"
	CellTypeCode     = "code"
)
View Source
const OutputTypeDisplayData = "display_data"
View Source
const OutputTypeError = "error"
View Source
const OutputTypeExecuteResult = "execute_result"
View Source
const OutputTypeStream = "stream"
View Source
const V4 = 4

Variables

View Source
var DefaultOpts = &Options{
	ValidateAgainst: nil,
	Version:         V4,
}
View Source
var ErrMissingCellsKey = errors.New("missing `cells` key")
View Source
var KeyNotFound = errors.New("key not found")

Functions

func DecodeBase64EncodedPng

func DecodeBase64EncodedPng(s string) (image.Image, error)

func DupBytes

func DupBytes(src []byte) []byte

func LoadSchema

func LoadSchema(schema []byte) (*jsonschema.Schema, error)

func LoadSchemaFromFile

func LoadSchemaFromFile(filePath string) (*jsonschema.Schema, error)

func PassesNBConvert

func PassesNBConvert(nbPath, jupyterConvertPath string) (string, bool)

func PathRelativeToTest

func PathRelativeToTest(t *testing.T, relPath ...string) string

func ProduceNotebookPaths

func ProduceNotebookPaths(ctx context.Context, rootDir string, bufSize int) <-chan string

I wrote this to analyze a large collection of Jupyter notebooks cloned from github as repositories.

func TempDir

func TempDir(t *testing.T) (string, func())

Types

type Cell

type Cell struct {
	Type string `json:"cell_type"`

	// MUST BE integer or null in JSON.
	// Renamed from 'prompt_number' in 4.0; TODO: Test
	ExecutionCount int `json:"execution_count"`

	// Renamed from `input` in nbformat: 4.0; TODO: Test
	Source []string `json:"source"`

	Outputs []Output `json:"outputs"`

	MetaData StringMap `json:"metadata"`

	Raw []byte `json:"-"`
}

func (*Cell) ClearRaw

func (c *Cell) ClearRaw() []byte

func (*Cell) UnmarshalJSON

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

type KernelSpec

type KernelSpec struct {
	Name  string `json:"name"`
	Extra StringMap
}

type LanguageInfo

type LanguageInfo struct {
	Name  string `json:"name"`
	Extra StringMap
}

type MetaData

type MetaData struct {
	LanguageInfo
	KernelSpec
	Extra StringMap

	Raw []byte `json:"-"`
}

func (*MetaData) ClearRaw

func (m *MetaData) ClearRaw() []byte

func (*MetaData) UnmarshalJSON

func (m *MetaData) UnmarshalJSON(b []byte) error

type Notebook

type Notebook struct {
	VersionMajor int      `json:"nbformat"`
	VersionMinor int      `json:"minor"`
	MetaData     MetaData `json:"metadata"`
	Cells        []Cell   `json:"cells"`

	Raw []byte `json:"-"`
}

TODO: Do any notebooks put any other keys at the top level?

func Read

func Read(filePath string, opts *Options) (*Notebook, error)

TODO: make version work.

func ReadBytes

func ReadBytes(b []byte, opts *Options) (*Notebook, error)

func (*Notebook) ClearAllRaw

func (nb *Notebook) ClearAllRaw()

func (*Notebook) ClearRaw

func (nb *Notebook) ClearRaw() []byte

func (*Notebook) ClearRawCells

func (nb *Notebook) ClearRawCells()

type Options

type Options struct {
	ValidateAgainst *jsonschema.Schema
	Version         int
	DiscardRaw      bool
}

type Output

type Output struct {

	// All fields *must* have an output_type.
	Type string `json:"output_type"`

	// Renamed from stream in 4.0
	Name string `json:"name"`

	Text []string `json:"text"`

	// in display data
	Metadata StringMap
	Data     StringMap

	// in execute result; used to be pyout / prompt_number
	ExecutionCount int `json:"execute_count"`

	// In errors
	EName     string   `json:"ename"`
	EValue    string   `json:"evalue"`
	Traceback []string `json:"traceback"`
}

func (*Output) UnmarshalJSON

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

type StringMap

type StringMap map[string]interface{}

Jump to

Keyboard shortcuts

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