Skip to content

Commit f27925b

Browse files
committed
Add a metadata field to kernelspecs.
Currently, the only way for a kernel to offer additional information about its capabilities is to encode information into the kernel name or display name; this information can be useful to clients, especially for things like filtering a list of kernels. This adds support for a new kernelspec dict field, `metadata`. This allows kernels to add additional information, which clients can then consume as needed.
1 parent ee9bd1e commit f27925b

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

docs/api/kernelspec.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ kernelspec - discovering kernels
2525
The name of the language the kernel implements, to help with picking
2626
appropriate kernels when loading notebooks.
2727

28+
.. attribute:: metadata
29+
30+
Additional kernel-specific metadata; clients can use this as needed,
31+
for instance to aid in kernel selection and filtering.
32+
2833
.. attribute:: resource_dir
2934

3035
The path to the directory with this kernel's resources, such as icons.

docs/kernels.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ JSON serialised dictionary containing the following keys and values:
135135
- **env** (optional): A dictionary of environment variables to set for the kernel.
136136
These will be added to the current environment variables before the kernel is
137137
started.
138+
- **metadata** (optional): A dictionary of additional attributes about this
139+
kernel; used by clients to aid clients in kernel selection.
138140

139141
For example, the kernel.json file for IPython looks like this::
140142

jupyter_client/kernelspec.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class KernelSpec(HasTraits):
2828
language = Unicode()
2929
env = Dict()
3030
resource_dir = Unicode()
31+
metadata = Dict()
3132

3233
@classmethod
3334
def from_resource_dir(cls, resource_dir):
@@ -45,6 +46,7 @@ def to_dict(self):
4546
env=self.env,
4647
display_name=self.display_name,
4748
language=self.language,
49+
metadata=self.metadata,
4850
)
4951

5052
return d

jupyter_client/tests/test_kernelspec.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def test_get_kernel_spec(self):
6767
self.assertEqual(ks.argv, sample_kernel_json['argv'])
6868
self.assertEqual(ks.display_name, sample_kernel_json['display_name'])
6969
self.assertEqual(ks.env, {})
70+
self.assertEqual(ks.metadata, {})
7071

7172
def test_find_all_specs(self):
7273
kernels = self.ksm.get_all_specs()

0 commit comments

Comments
 (0)