Interactive Go programming with Jupyter

For the past few years, the programming language Go (golang) is growing in popularity. I was a big fan of Python and I primarily used Python in my hobby projects three years ago. Now, I use Go instead of Python because I can be productive with Go from small-scale hobby projects to very large-scale projects in a large company.

In the same period, Python is also growing in popularity as machine learning and data science became important. There are a lot of reasons why Python is preferred in ML. One reason is Python is designed for interactive code writing and evaluation. Another important reason is there is a great tool for interactive programming in Python. Jupyter Notebook.

Although I now use Go in many projects where I would have used Python before, I still need to use Python for machine learning and data analysis. The ability of interactive programming and Jupyter Notebook in Python are still very attractive to me. I looked for Go Jupyter environment which really works and checked existing golang Jupyter kernels. But there was no such kernel in the world. Some projects were terminated. Some of them are somewhat popular but did not fit to actual use because they do not support either type-safety, code cancellation, code completion, inspection or displaying non-text contents.

Thus, I decided to develop a new environment to run Go interactively on Jupyter Notebook from scratch. Today, I’m introducing the software I built and the new way to write and execute Go interactively like Python.

Project homepage on GitHub

Try it from browsers

Thanks to binder (mybinder.org), you can try the Go+Jupyter environment (lgo) on your browsers with temporary docker containers on binder. Open your temporary Jupyter Notebook from the button above and enjoy interactive Go programming!

Main Features

  • Write and execute Go (golang) interactively like Python.
  • Jupyter Notebook integration
  • Full Go (golang) language spec support. 100% gc (go compiler) compatible.
  • Code completion, inspection and code formatting in Jupyter Notebooks
  • Display images, HTML, JavaScript, SVG, etc…
  • interactive REPL mode from console
  • goroutines and channels are fully supported

Installation

There are two ways to install the Go language Jupyter environment into your computer.

If you want to try the Go+Jupyter environment quickly on your computer, try the Docker version first. If you use Linux and you want to integrate the Jupyter environment with the Go environment in your computer, please install it from source. The code execution of lgo is slow in go1.10 due to the regression with-buildmode=shared. Until the bug is fixed in go1.10, please try lgo with go1.9. It works nicely with go1.9 and go1.8.

In Windows and Mac, please use Docker version because lgo does not support Windows and Mac natively. You can edit notebooks in Windows/Mac from lgo running in Docker.

Usage

Execute jupyter notebook command to start Jupyter Notebook as usual. When you create a new notebook, please select Go (lgo) from the menu. Once a new notebook is created, you can write and execute Go interactively like Python.

In lgo, you can show documentation of variables, functions and types by moving the cursor to the identifiers and pressing Shift-Tab. You can complete code in lgo by pressing Tab. To display non-text data, use _ctx.Display like this example.

Use as a REPL environment from console

You can use lgo as a REPL from console. Run jupyter console --kernel lgo after you install lgo. Of course, you can use code completion in this mode by pressing Tab or Ctrl-I.

Comparison with an existing framework

For those people who know other existing golang Jupyter kernel, here is the comparison table with competitors. Read this section in README.md for details.

Learn more

Visit the project homepage and read the instruction in README.md. Also, you can learn what we can really do with the Go+Jupyter environment from these example notebooks. Enjoy interactive Go programming!