##// END OF EJS Templates
Initial patch with Jedi completion (no function header description)....
Initial patch with Jedi completion (no function header description). Handle case when Jedi is not importable. Fix print statement vs function discrepancy. Add two-column display for function and description, remove sys.path manipulation. cleanup comments, add matcher APi instead of checking every time (#1) * Improve completion a bit to take care of what was previously "greedy" This is a bit hackins because of how IPython decides what is going to be replaced, and because completions need to strart with `text`. Add a few test cases. * require path.py * Add completion tests. * Fix some completion, in particular imports. Also completion after assignments. Add TODO about how to using Completions with Jedi.

File last commit:

r21636:ec0fabd0
r22292:f8225dae
Show More
wrapperkernels.rst
175 lines | 6.0 KiB | text/x-rst | RstLexer

Making simple Python wrapper kernels

You can now re-use the kernel machinery in IPython to easily make new kernels. This is useful for languages that have Python bindings, such as Octave (via Oct2Py), or languages where the REPL can be controlled in a tty using pexpect, such as bash.

Required steps

Subclass :class:`ipykernel.kernelbase.Kernel`, and implement the following methods and attributes:

To launch your kernel, add this at the end of your module:

if __name__ == '__main__':
    from ipykernel.kernelapp import IPKernelApp
    IPKernelApp.launch_instance(kernel_class=MyKernel)

Example

echokernel.py will simply echo any input it's given to stdout:

from ipykernel.kernelbase import Kernel

class EchoKernel(Kernel):
    implementation = 'Echo'
    implementation_version = '1.0'
    language = 'no-op'
    language_version = '0.1'
    language_info = {'mimetype': 'text/plain'}
    banner = "Echo kernel - as useful as a parrot"

    def do_execute(self, code, silent, store_history=True, user_expressions=None,
                   allow_stdin=False):
        if not silent:
            stream_content = {'name': 'stdout', 'text': code}
            self.send_response(self.iopub_socket, 'stream', stream_content)

        return {'status': 'ok',
                # The base class increments the execution count
                'execution_count': self.execution_count,
                'payload': [],
                'user_expressions': {},
               }

if __name__ == '__main__':
    from ipykernel.kernelapp import IPKernelApp
    IPKernelApp.launch_instance(kernel_class=EchoKernel)

Here's the Kernel spec kernel.json file for this:

{"argv":["python","-m","echokernel", "-f", "{connection_file}"],
 "display_name":"Echo"
}

Optional steps

You can override a number of other methods to improve the functionality of your kernel. All of these methods should return a dictionary as described in the relevant section of the :doc:`messaging spec <messaging>`.