MetaKernel Echo Demo¶
The kernel running this notebook is MetaKernel Echo — a MetaKernel subclass that purely echoes its input back as output. It is useful as a minimal reference implementation for building new kernels on top of MetaKernel.
Despite its simplicity, it inherits the full MetaKernel magic system.
Installation¶
Install the echo kernel by running pip install . from that directory.
Then run ipython notebook from this directory.
Select "Echo" from the top right dropdown list of kernels.
Hello, world!
'Hello, world!'
Magics¶
Like all of the Metakernels, the echo kernel comes with a base set of magics.
%magic
Line magics:
%activity FILENAME - run a widget-based activity
%blockly - show visual code
%cd PATH - change current directory of session
%connect_info - show connection information
%conversation ID - insert conversation by ID
%dot CODE - render code as Graphviz image
%download URL [-f FILENAME] - download file from URL
%edit FILENAME - load code from filename into next cell for editing
%get VARIABLE - get a variable from the kernel in a Python-type.
%help TEXT - get help on the given text
%html CODE - display code as HTML
%include FILENAME ... - include code from filename into this code
%install PACKAGE - install package
%install_magic URL - download and install magic from URL
%javascript CODE - send code as JavaScript
%jigsaw LANGUAGE - show visual code editor/generator
%kernel MODULE CLASS [-k NAME] - construct a kernel for sending code.
%kx CODE [-k NAME] - send the code to the kernel.
%latex TEXT - display text as LaTeX
%load FILENAME - load code from filename into next cell
%ls PATH - list files and directories under PATH
%lsmagic - list the current line and cell magics
%macro NAME - execute a macro
%magic - show installed magics
%matplotlib BACKEND - set the matplotlib backend to BACKEND
%parallel MODULE CLASS [-k NAME] [-i [...]] - construct an interface to the cluster.
%plot [options] backend - configure plotting for the session.
%pmap FUNCTION [ARGS1,ARGS2,...] - ("parallel map") call a FUNCTION on args
%px EXPRESSION - send EXPRESSION to the cluster.
%python CODE - evaluate code as Python
%reload_magics - reload the magics from the installed files
%restart - restart session
%run [--language LANG] FILENAME - run code in filename by
%scheme CODE - evaluate code as Scheme
%set VARIABLE VALUE - set a variable in the kernel.
%shell COMMAND - run the line as a shell command
Cell magics:
%%shell - run the contents of the cell as shell commands
%%activity FILENAME - make an activity from
%%brain - run a cell as brain control code
%%debug - step through the code expression by expression
%%dot - render contents of cell as Graphviz image
%%file [--append|-a] FILENAME - write contents of cell to file
%%help TEXT - get detailed help on the given text
%%html - display contents of cell as HTML
%%javascript - send contents of cell as JavaScript
%%kx [-k NAME] - send the cell code to the kernel.
%%latex - display contents of cell as LaTeX
%%macro NAME - learn a new macro
%%pipe FUNCTION1 | FUNCTION2 ...
%%processing - run the cell in the language Processing
%%px - send cell to the cluster.
%%python - evaluate contents of cell as Python
%%scheme - evaluate contents of cell as Scheme
%%show [-o]- show cell contents or results in system pager
%%time - show time to run cell
%%tutor [--language=LANGUAGE] - show cell with
%conversation ID - insert conversation by ID
Shell shortcut:
! COMMAND ... - execute command in shell
Any cell magic can be made persistent for rest of session by using %%% prefix.
Help on items:
??item - get detailed, technical information on item
?item - get help on item
item? - get help on item
item?? - get detailed, technical information on item
%python print('hello, world!')
hello, world!
You can get help on a magic by typing ?
%%html?
You can also get help by pressing SHIFT+TAB at the end of the word.
%lsmagic
Available line magics: %activity %blockly %cd %connect_info %conversation %dot %download %edit %get %help %html %include %install %install_magic %javascript %jigsaw %kernel %kx %latex %load %ls %lsmagic %macro %magic %matplotlib %parallel %plot %pmap %px %python %reload_magics %restart %run %scheme %set %shell Available cell magics: %%activity %%brain %%conversation %%debug %%dot %%file %%help %%html %%javascript %%kx %%latex %%macro %%pipe %%processing %%px %%python %%scheme %%shell %%show %%time %%tutor
Code completion works for magics. Press tab below to see the completion (when not viewing through nbviewer).
%javas
'%javas'
Completion also works for path names (local, absolute, or from the home ~ directory). Press TAB below for completion.
echo_kernel.ip
'echo_kernel.ip'
%%file temp.txt
This concludes our example.
Goodbye, world!
Created file '/Users/stevensilvester/workspace/metakernel/examples/temp.txt'.