skip to main content

@tonyfast s notebooks

site navigation
notebook summary
title
extensible metadata in the notebook format
description
this document is the minimum schema to make metadata extensible. it makes clearer distinctions between the notebook, cell and display metadata.
cells
8 total
4 code
state
executed in order
kernel
Python [conda env:root] *
language
python
name
conda-root-py
lines of code
39
outputs
5
table of contents
{"kernelspec": {"display_name": "Python [conda env:root] *", "language": "python", "name": "conda-root-py"}, "language_info": {"codemirror_mode": {"name": "ipython", "version": 3}, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.13"}, "widgets": {"application/vnd.jupyter.widget-state+json": {"state": {}, "version_major": 2, "version_minor": 0}}, "title": "extensible metadata in the notebook format", "description": "this document is the minimum schema to make metadata extensible.\nit makes clearer distinctions between the notebook, cell and display metadata."}
notebook toolbar
Activate
cell ordering
1

extensible metadata in the notebook format

2

this document is the minimum schema to make metadata extensible. it makes clearer distinctions between the notebook, cell and display metadata.

new metadata schema are combined using the allOf key that references schema from other places.

3 1 outputs.
4

the extended schema is written below in toml.

5 1 outputs.
schema = strip_fence | tomli.loads | \
description = "extensible metadata for the notebook schema."

["$defs".notebook-meta]
"$anchor" = "notebook-meta"
allOf = [
    {"$ref" = "kernelspec.json"}
]

["$defs".code-meta]
"$anchor" = "code-meta"
allOf = [
    {"$ref" = "#slides"}
]

["$defs".display-meta]
"$anchor" = "display-meta"
allOf = [
    {"$ref" = "#images"},
    {"$ref" = "#json"}
]

["$defs".slides]
"$anchor" = "slides"
properties.slides.enum = ["slide", "subslide", "fragment"]

[properties]
metadata."$ref" = "#notebook-meta"

[properties.cells.items.properties.metadata]
"$ref" = "#cell-meta"

[properties.cells.items.properties.outputs.items.properties.metadata]
outputs.items.properties.metadata."$ref" = "#display-meta"
6

it is shown in json below.

7 3 outputs.
{'$defs': {'code-meta': {'$anchor': 'code-meta',
                         'allOf': [{'$ref': '#slides'}]},
           'display-meta': {'$anchor': 'display-meta',
                            'allOf': [{'$ref': '#images'}, {'$ref': '#json'}]},
           'notebook-meta': {'$anchor': 'notebook-meta',
                             'allOf': [{'$ref': 'kernelspec.json'}]},
           'slides': {'$anchor': 'slides',
                      'properties': {'slides': {'enum': ['slide',
                                                         'subslide',
                                                         'fragment']}}}},
 'description': 'extensible metadata for the notebook schema.',
 'properties': {'cells': {'items': {'properties': {'metadata': {'$ref': '#cell-meta'},
                                                   'outputs': {'items': {'properties': {'metadata': {'outputs': {'items': {'properties': {'metadata': {'$ref': '#display-meta'}}}}}}}}}}},
                'metadata': {'$ref': '#notebook-meta'}}}

<IPython.core.display.JSON object>
pprint.pprint(schema)
JSON(schema, expanded=False)
8