API Reference

Metakernel

class metakernel.MetaKernel(*args, **kwargs)[source]
classmethod run_as_main()[source]

Launch or install a metakernel.

Modules implementing a metakernel subclass can use the following lines:

if __name__ == ‘__main__’:
MetaKernelSubclass.run_as_main()
makeSubkernel(kernel)[source]

Run this method in an IPython kernel to set this kernel’s input/output settings.

set_variable(name, value)[source]

Set a variable to a Python-typed value.

get_variable(name)[source]

Lookup a variable name and return a Python-typed value.

handle_plot_settings()[source]

Handle the current plot settings

get_local_magics_dir()[source]

Returns the path to local magics dir (eg ~/.ipython/metakernel/magics)

get_completions(info)[source]

Get completions from kernel based on info dict.

do_execute_direct(code, silent=False)[source]

Execute code in the kernel language.

do_execute_file(filename)[source]

Default code for running a file. Just opens the file, and sends the text to do_execute_direct.

do_execute_meta(code)[source]

Execute meta code in the kernel. This uses the execute infrastructure but allows JavaScript to talk directly to the kernel bypassing normal processing.

When responding to the %%debug magic, the step and reset meta commands can answer with a string in the format:

“highlight: [start_line, start_col, end_line, end_col]”

for highlighting expressions in the frontend.

initialize_debug(code)[source]

This function is used with the %%debug magic for highlighting lines of code, and for initializing debug functions.

Return the empty string if highlighting is not supported.

do_function_direct(function_name, arg)[source]

Call a function in the kernel language with args (as a single item).

restart_kernel()[source]

Restart the kernel

do_history(hist_access_type, output, raw, session=None, start=None, stop=None, n=None, pattern=None, unique=False)[source]

Access history at startup.

do_shutdown(restart)[source]

Shut down the app gracefully, saving history.

do_is_complete(code)[source]

Given code as string, returns dictionary with ‘status’ representing whether code is ready to evaluate. Possible values for status are:

‘complete’ - ready to evaluate ‘incomplete’ - not yet ready ‘invalid’ - invalid code ‘unknown’ - unknown; the default unless overridden

Optionally, if ‘status’ is ‘incomplete’, you may indicate an indentation string.

Example:

return {‘status’ : ‘incomplete’,
‘indent’: ‘ ‘ * 4}
call_magic(line)[source]

Given an line, such as “%download http://example.com/”, parse and execute magic.

class metakernel.Magic(kernel)[source]
get_completions(info)[source]

Get completions based on info dict from magic.

metakernel.option(*args, **kwargs)[source]

Return decorator that adds a magic option to a function.