{
  "__type": "IngestedDoc",
  "__tag": 4010,
  "_content": {},
  "_ordered_sections": [],
  "item_file": null,
  "item_line": null,
  "item_type": null,
  "aliases": [],
  "example_section_data": {
    "__type": "Section",
    "__tag": 4015,
    "children": [],
    "title": [],
    "level": 0,
    "target": null
  },
  "see_also": [],
  "signature": null,
  "references": null,
  "qa": "development:wrapperkernels",
  "arbitrary": [
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "versionadded",
          "base_type": "neutral",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "versionadded 3.0"
                }
              ]
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "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 "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Octave"
                }
              ],
              "url": "http://www.gnu.org/software/octave/",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " (via "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "Oct2Py"
                }
              ],
              "url": "http://blink1073.github.io/oct2py/",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "), or languages where the REPL can be controlled in a tty using "
            },
            {
              "__type": "Link",
              "__tag": 4049,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "pexpect"
                }
              ],
              "url": "https://pexpect.readthedocs.io/en/latest/",
              "title": ""
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", such as bash."
            }
          ]
        },
        {
          "__type": "Admonition",
          "__tag": 4056,
          "kind": "seealso",
          "base_type": "note",
          "children": [
            {
              "__type": "AdmonitionTitle",
              "__tag": 4055,
              "children": [
                {
                  "__type": "Text",
                  "__tag": 4046,
                  "value": "seealso "
                }
              ]
            },
            {
              "__type": "DefList",
              "__tag": 4033,
              "children": [
                {
                  "__type": "DefListItem",
                  "__tag": 4037,
                  "dt": {
                    "__type": "Paragraph",
                    "__tag": 4045,
                    "children": [
                      {
                        "__type": "Link",
                        "__tag": 4049,
                        "children": [
                          {
                            "__type": "Text",
                            "__tag": 4046,
                            "value": "bash_kernel"
                          }
                        ],
                        "url": "https://github.com/takluyver/bash_kernel",
                        "title": ""
                      }
                    ]
                  },
                  "dd": [
                    {
                      "__type": "Paragraph",
                      "__tag": 4045,
                      "children": [
                        {
                          "__type": "Text",
                          "__tag": 4046,
                          "value": "A simple kernel for bash, written using this machinery"
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Making simple Python wrapper kernels"
        }
      ],
      "level": 0,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Subclass "
            },
            {
              "__type": "InlineRole",
              "__tag": 4003,
              "value": "ipykernel.kernelbase.Kernel",
              "domain": null,
              "role": "class",
              "inventory": null
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": ", and implement the following methods and attributes:"
            }
          ]
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "To launch your kernel, add this at the end of your module      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "if __name__ == '__main__':\n    from ipykernel.kernelapp import IPKernelApp\n    IPKernelApp.launch_instance(kernel_class=MyKernel)",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Required steps"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "echokernel.py"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " will simply echo any input it's given to stdout      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "from ipykernel.kernelbase import Kernel\n\nclass EchoKernel(Kernel):\n    implementation = 'Echo'\n    implementation_version = '1.0'\n    language = 'no-op'\n    language_version = '0.1'\n    language_info = {'mimetype': 'text/plain'}\n    banner = \"Echo kernel - as useful as a parrot\"\n\n    def do_execute(self, code, silent, store_history=True, user_expressions=None,\n                   allow_stdin=False):\n        if not silent:\n            stream_content = {'name': 'stdout', 'text': code}\n            self.send_response(self.iopub_socket, 'stream', stream_content)\n\n        return {'status': 'ok',\n                # The base class increments the execution count\n                'execution_count': self.execution_count,\n                'payload': [],\n                'user_expressions': {},\n               }\n\nif __name__ == '__main__':\n    from ipykernel.kernelapp import IPKernelApp\n    IPKernelApp.launch_instance(kernel_class=EchoKernel)",
          "execution_status": null
        },
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "Here's the Kernel spec "
            },
            {
              "__type": "InlineCode",
              "__tag": 4051,
              "value": "kernel.json"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": " file for this      "
            }
          ]
        },
        {
          "__type": "Code",
          "__tag": 4050,
          "value": "{\"argv\":[\"python\",\"-m\",\"echokernel\", \"-f\", \"{connection_file}\"],\n \"display_name\":\"Echo\"\n}",
          "execution_status": null
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Example"
        }
      ],
      "level": 1,
      "target": null
    },
    {
      "__type": "Section",
      "__tag": 4015,
      "children": [
        {
          "__type": "Paragraph",
          "__tag": 4045,
          "children": [
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "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 "
            },
            {
              "__type": "CrossRef",
              "__tag": 4002,
              "value": "messaging spec",
              "reference": {
                "__type": "LocalRef",
                "__tag": 4022,
                "kind": "docs",
                "path": "messaging"
              },
              "kind": "docs"
            },
            {
              "__type": "Text",
              "__tag": 4046,
              "value": "."
            }
          ]
        }
      ],
      "title": [
        {
          "__type": "Text",
          "__tag": 4046,
          "value": "Optional steps"
        }
      ],
      "level": 1,
      "target": null
    }
  ],
  "local_refs": []
}