Skip to content

extensible metadata in the notebook formatยค

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.

the extended schema is written below in toml.

schema = strip_fence | tomli.loads | \

toml 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"

it is shown in json below.

{'$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)