API Reference¶
Metakernel¶
-
class
metakernel.
MetaKernel
(*args, **kwargs)[source]¶ The base MetaKernel class.
Create a configurable given a config config.
- Parameters
- configConfig
If this is empty, default values are used. If config is a
Config
instance, it will be used to configure the instance.- parentConfigurable instance, optional
The parent Configurable instance of this object.
Notes
Subclasses of Configurable must call the
__init__()
method ofConfigurable
before doing anything else and usingsuper()
:class MyConfigurable(Configurable): def __init__(self, config=None): super(MyConfigurable, self).__init__(config=config) # Then any other code you need to finish initialization.
This ensures that instances will be configured properly.
-
classmethod
run_as_main
(\*args, \*\*kwargs)[source]¶ Launch or install a metakernel.
Modules implementing a metakernel subclass can use the following lines:
- if __name__ == ‘__main__’:
MetaKernelSubclass.run_as_main()
-
makeSubkernel
(self, kernel)[source]¶ Run this method in an IPython kernel to set this kernel’s input/output settings.
-
get_kernel_help_on
(self, info, level=0, none_on_fail=False)[source]¶ Get help on an object. Called by the help magic.
-
get_local_magics_dir
(self)[source]¶ Returns the path to local magics dir (eg ~/.ipython/metakernel/magics)
-
do_execute_file
(self, filename)[source]¶ Default code for running a file. Just opens the file, and sends the text to do_execute_direct.
-
do_execute_meta
(self, 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
(self, 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
(self, function_name, arg)[source]¶ Call a function in the kernel language with args (as a single item).
-
do_execute
(self, code, silent=False, store_history=True, user_expressions=None, allow_stdin=False)[source]¶ Handle code execution.
https://jupyter-client.readthedocs.io/en/stable/messaging.html#execute
-
post_execute
(self, retval, code, silent)[source]¶ Post-execution actions
Handle special kernel variables and display response if not silent.
-
do_history
(self, hist_access_type, output, raw, session=None, start=None, stop=None, n=None, pattern=None, unique=False)[source]¶ Access history at startup.
https://jupyter-client.readthedocs.io/en/stable/messaging.html#history
-
do_shutdown
(self, restart)[source]¶ Shut down the app gracefully, saving history.
https://jupyter-client.readthedocs.io/en/stable/messaging.html#kernel-shutdown
-
do_is_complete
(self, 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}
https://jupyter-client.readthedocs.io/en/stable/messaging.html#code-completeness
-
do_complete
(self, code, cursor_pos)[source]¶ Handle code completion for the kernel.
https://jupyter-client.readthedocs.io/en/stable/messaging.html#completion
-
do_inspect
(self, code, cursor_pos, detail_level=0)[source]¶ Object introspection.
https://jupyter-client.readthedocs.io/en/stable/messaging.html#introspection
-
Display
(self, \*objects, \*\*kwargs)[source]¶ Display one or more objects using rich display.
Supports a clear_output keyword argument that clears the output before displaying.
See https://ipython.readthedocs.io/en/stable/config/integrating.html?highlight=display#rich-display
-
Print
(self, \*objects, \*\*kwargs)[source]¶ Print objects to the iopub stream, separated by sep and followed by end.
Items can be strings or Widget instances.
-
Write
(self, message)[source]¶ Write message directly to the iopub stdout with no added end character.
-
Error
(self, \*objects, \*\*kwargs)[source]¶ Print objects to stdout, separated by sep and followed by end.
Objects are cast to strings.
-
Error_display
(self, \*objects, \*\*kwargs)[source]¶ Print objects to stdout is they area strings, separated by sep and followed by end. All other objects are rendered using the Display method Objects are cast to strings.
-
send_response
(self, \*args, \*\*kwargs)[source]¶ Send a response to the message we’re currently processing.
This accepts all the parameters of
jupyter_client.session.Session.send()
exceptparent
.This relies on
set_parent()
having been called for the current message.
-
call_magic
(self, line)[source]¶ Given an line, such as “%download http://example.com/”, parse and execute magic.
-
class
metakernel.
Magic
(kernel)[source]¶ Base class to define magics for MetaKernel based kernels.
Users can redefine the default magics provided by Metakernel by creating a module with the exact same name as the Metakernel magic.
For example, you can override %matplotlib in your kernel by writing a new magic inside magics/matplotlib_magic.py