Git Product home page Git Product logo

gonb's Introduction

GoNB - A Go Notebook Kernel for Jupyter

Go Dev Go Report Card Binder

For a quick start, see the very simple tutorial!

Go is a compiled language, but with very fast compilation, that allows one to use it in a REPL (Read-Eval-Print-Loop) fashion, by inserting a "Compile" step in the middle of the loop -- so it's a Read-Compile-Run-Print-Loop -- while still feeling very interactive.

GoNB leverages that compilation speed to implement a full-featured (at least it's getting there) Jupyter notebook kernel. As a side benefit it works with packages that use CGO -- although it won't parse C code in the cells, so it can't be used as a C kernel.

It already includes many goodies: cache between cell of results, contextual help and auto-complete (with gopls), compilation error context (by mousing over), bash command execution, images, html, etc. See the tutorial.

It's been heavily (and successfully) used by the author, but should still be seen as experimental -- if we hear success stories from others we can change this. Reports of issues as well as fixes are always welcome.

There is also a live version in Google's Colab that one can interact with (make a copy first) -- if link doesn't work (Google Drive sharing publicly is odd), download it from github and upload it to Google's Colab.

It also works in VSCode and Github's Codespaces. Just follow the installation below.

Installation

Only for Linux and MacOS. In Windows it works in WSL or inside a Docker

Docker

GoNB offers a pre-built docker, that includes Jupyter and GoNB. To use it, go to a directory that you want to make available to the Jupyter notebook (your home directory, or a directory where to store the notebook files). It will be mounted on the work/ sub-directory in JupyterLab.

To start it:

docker pull janpfeifer/gonb_jupyter:latest
docker run -it --rm -p 8888:8888 -v "${PWD}":/home/jovyan/work janpfeifer/gonb_jupyterlab:latest

Then copy&paste the URL it outputs in your browser.

Linux and Mac installation

The tutorial explains, but in short:

$ go install github.com/janpfeifer/gonb@latest
$ go install golang.org/x/tools/cmd/goimports@latest
$ go install golang.org/x/tools/gopls@latest
$ gonb --install

Or all in one line that can be copy&pasted:

go install github.com/janpfeifer/gonb@latest && go install golang.org/x/tools/cmd/goimports@latest && go install golang.org/x/tools/gopls@latest && gonb --install

And then (re-)start Jupyter.

In Github's Codespace, if Jupyter is already started, restarting the docker is an easy way to restart Jupyter.

Windows

The recommendation is to use WSL (Windows Subsystem for Linux) or WSL2, and run Jupyter and the GoNB kernel in Linux. Installation there as if in a linux machine.

A pure Windows installation is not supported at this time -- but contribution to add support would be welcome :)

Rich display: HTML, Images, SVG, Videos, manipulating javascript, etc.

GoNB opens a named pipe (set in environment variable GONB_PIPE) that a program can use to directly display any type of HTML content.

For the most cases, one can simply import github.com/janpfeifer/gonb/gonbui: the library offers a convenient API to everything available. Examples of use in the tutorial.

If implementing some new mime type (or some other form of interaction), see kernel/display.go for the protocol details.

TODOs

Contributions are welcome!

Implementation

The Jupyter kernel started from gophernotes implementation, but was heavily modified and very little from it is left. Also, the execution loop and mechanisms are completely different and new: GoNB compiles and executes on-the-fly, instead of using a REPL engine.

gonb's People

Contributors

janpfeifer avatar manics avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.