Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nakkaya/inf-ipy

A REPL interface to communicate with Jupyter kernels in Emacs or CLI.
https://github.com/nakkaya/inf-ipy

Last synced: 3 months ago
JSON representation

A REPL interface to communicate with Jupyter kernels in Emacs or CLI.

Awesome Lists containing this project

README

        

A REPL interface to communicate with Jupyter kernels in Emacs or CLI.

#+BEGIN_HTML


#+END_HTML

* Table of Contents :TOC:

- [[#Installation][Installation]]
- [[#Quickstart][Quickstart]]
- [[#CLI][Command Line Interface]]
- [[#Emacs][Emacs Interface]]

#+attr_html: :width 80%
[[https://s3.amazonaws.com/dropbox.nakkaya.com/inf-ipy.png]]

* Installation

=inf-ipy= is made up of two parts. Python part that handles
communication with Jupyter and provides two REPL interfaces one
specialized for use in command line and one specialized for in Emacs.

Machines that will run the kernels or connect to them only requires
=SSH= and =Jupyter= to be installed. Tested on =Linux= / =Windows=.

** Using Package Managers

Python

#+BEGIN_SRC bash
pip install inf-ipy
#+END_SRC

Emacs Using [[https://github.com/quelpa/quelpa][quelpa]]

#+BEGIN_SRC emacs-lisp
(quelpa
'(inf-ipy
:fetcher github
:repo "nakkaya/inf-ipy"
:files ("src/emacs/*.el")))
#+END_SRC

Emacs from MELPA (Pending Approval)

#+BEGIN_EXAMPLE
M-x package-install RET inf-ipy RET
#+END_EXAMPLE

** Manual

Clone this repository then install individual parts.

For python,

#+BEGIN_SRC bash
cd src/python
pip install .
#+END_SRC

For Emacs,

#+BEGIN_SRC emacs-lisp
(load-file "src/emacs/inf-ipy.el")
#+END_SRC

* Quickstart

Create a configuration file =config.ini= that describes how to login
and launch a kernel on a machine.

#+BEGIN_SRC conf
[SERVER]
;; SSH IP
host = 10.9.0.150
;; SSH User
user = core
;; Use named kernel connection file instead of random file name
file = server.json
#+END_SRC

For a complete list of options use =inf-ipy --help=. All options can
be supplied via the configuration file or command line switches.

To start a kernel and download the connection file.

#+BEGIN_SRC bash
inf-ipy --start
#+END_SRC

To stop the kernel.

#+BEGIN_SRC bash
inf-ipy --stop
#+END_SRC

To select a different kernel other than Python =--kernel= option
can be used. To start a Matlab kernel use.

#+BEGIN_SRC bash
inf-ipy --start --kernel matlab_kernel.kernel.MatlabKernel
#+END_SRC

** CLI

To interact with the kernel via command line.

#+BEGIN_SRC bash
inf-ipy --repl
#+END_SRC

** Emacs

#+BEGIN_SRC emacs-lisp
(require 'inf-ipy)
#+END_SRC

Once a kernel is started (using a configuration file) an Emacs REPL to
that kernel can be created using =M-x inf-ipy-repl=.

Integration with =org-babel= can be enabled using,

#+BEGIN_SRC emacs-lisp
;; Enable org-babel support for Python and Matlab
(inf-ipy-configure-kernel python)
(inf-ipy-configure-kernel matlab)
#+END_SRC

To interact with a python kernel you would create a new
source block using,

#+BEGIN_EXAMPLE
,#+BEGIN_SRC inf-ipy-python :results output
%matplotlib inline

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax = plt.axes()

x = np.linspace(0, 10, 1000)
ax.plot(x, np.sin(x));
,#+END_SRC
#+END_EXAMPLE