[IPython-dev] IPython3/Jupyter Magics for Python-based kernels
Doug Blank
doug.blank at gmail.com
Wed Aug 20 07:22:00 EDT 2014
IPython developers,
One of the nice things that the IPython team did for the next version was
to create a base class for creating new kernels for code written in Python,
called wrapper kernels [1].
Unfortunately, such kernels don't have ! shell commands, nor magics. This
is understandable, as those are tightly integrated with IPython's Python.
However, one could get some of the basic functionality of these features on
top of the wrapper kernel, in a generic way. For example, you could run
shell commands, or have some magics that operate independent of the kernel.
We have created a prototype of magics for wrapper kernels [2]. The code is
in magickernel.py, and the magics are in the folder magics. The current
prototype works like this:
```
In [1]: %magics
Line magics:
%cd PATH - change current directory of session
%connect_info - show connection information
%download URL [FILENAME] - download file from URL
%html CODE - display code as HTML
%install_magic URL - download and install magic from URL
%javascript CODE - send code as JavaScript
%latex TEXT - display text as LaTex
%magics - show installed magics
%reload_magics - reload the magics from the installed files
%shell COMMAND - run the line as a shell command
%time COMMAND - show time to run line
Cell magics:
%%file FILENAME - write contents of cell to file
%%html - display contents of cell as HTML
%%javascript - send contents of cell as JavaScript
%%latex - display contents of cell as LaTeX
%%shell - run the contents of the cell as shell commands
%%time - show time to run cell
Shell shortcut:
! COMMAND ... - execute command in shell
Any cell magic can be made persistent for rest of session by using %%%
prefix.
```
The idea is to be able to easily add some standard-like magics to 3rd-party
kernels by using MagicKernel. See the sample wrapperkernel EchoKernel with
magics [3]. Also, the idea here is not to replicate too much what comes
with IPython's Python, but to provide a small, simple core set of magics
that can't be easily done in the kernel language. You can install
MagicKernel from source, or using:
$ pip install calico --upgrade
This is a prototype (with some bugs), and we very much hope for others to
provide feedback or code, and more work needs to be done. What magics would
you need in your 3rd-party kernel, that can be accomplished this way? Will
this design be sufficient?
We hope that this is useful!
-Doug
[1] - http://ipython.org/ipython-doc/dev/development/wrapperkernels.html
[2] - https://bitbucket.org/ipre/calico/src/master/src/calico/
[3] -
https://bitbucket.org/ipre/calico/src/master/src/echo_kernel/echo_kernel.py
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20140820/a5bb1166/attachment.html>
More information about the IPython-dev
mailing list