Skip to content

Accessing Jupyter Kernels from 3rd party extensions

Don Jayamanne edited this page Dec 15, 2021 · 1 revision

Third party extensions can now enumerate all of the Jupyter kernels, start a kernel and execute code against the kernels. The API kernel exposed conforms to the Kernel.IKernelConnection API provided by @jupyter/services package found here

The API exposed provides the following functionalities:

  • Enumerate kernel specifications
  • Enumerate active kernels (local and remote)
  • Ability to connect to an active kernel (remote)
  • Ability to start a kernel
  • Ability to get an instance of the active kernel as Kernel.IKernelConnection

All of the types are exposed in the following type definition file

Access to the API

The API is currently available to all extension authors while debugging VS Code extensions. However extensions can only use this API in VS Code insiders, and must register with the Jupyter extension (by reaching out to us). This is only done so that we don't break 3rd party extensions when changing this API, hence we request all extension authors to register with us to work closely for a smoother experience for extension authors and end users. Currently the list of extensions (publishers) allowed to access this API is defined in here https://github.com/microsoft/vscode-jupyter/blob/main/src/client/api/apiAccessService.ts#L22 and the plan is to update this over time.

Once the API is stable enough, we'll consider exposing for use in VS Code Stable.

Sample

import { extensions } from 'vscode';

const jupyter = extensions.getExtension<JupyterApi>('ms-toolsai.jupyter');
await jupyter.activate();
const kernelService = await jupyter.exports.getKernelService();

// Use the methods in kernelService
kernelService.start(.....)
Clone this wiki locally