Skip to content

Commit 1ff864d

Browse files
committed
Add JEP for adding $schema to notebook format
1 parent 15e8169 commit 1ff864d

File tree

1 file changed

+117
-0
lines changed

1 file changed

+117
-0
lines changed
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
---
2+
title: Add `$schema` to notebook format
3+
authors: Jason Grout (@jasongrout), Angus Hollans (@agoose77),
4+
Nicholas Bollweg (@bollwyvl), Filip Schouwenaars (@filipsch)
5+
issue-number: xxx
6+
pr-number: 94
7+
date-started: 2023-03-01
8+
---
9+
10+
# Summary
11+
12+
We propose to add a new top-level field, `$schema` to the notebook JSON, as such updating the notebook JSON schema. This new field deprecates `nbformat` and `nbformat_minor`.
13+
14+
# Motivation
15+
16+
Today, `nbformat` and `nbformat_minor` specify the JSON schema a notebook should adhere to (for example [4.5](https://github.com/jupyter/nbformat/blob/main/nbformat/v4/nbformat.v4.5.schema.json)). Since this approach was adopted in the Jupyter ecosystem, the JSON schema standard has evolved and Jupyter's approach is no longer in line with it. Other than following standards being the right thing to do, bringing the notebook format back in line with the current JSON Schema spec opens it up to the rich tooling that exists around JSON schema validation today.
17+
18+
# Guide-level explanation
19+
20+
The introduction of a new `$schema` top-level property takes precedence over the existing `"nbformat"` and `"nbformat_minor"` properties that specify the notebook format.
21+
22+
Example of notebook in 4.5 format:
23+
24+
```
25+
{
26+
"nbformat": 4
27+
"nbformat_minor": 5
28+
"metadata": { ... }
29+
"cells": [ ... ]
30+
}
31+
```
32+
33+
Example of notebook in 4.6 format:
34+
35+
```
36+
{
37+
"$schema": "https://jupyter.org/schema/notebook/4.6/notebook-4.6.schema.json"
38+
"nbformat": 4
39+
"nbformat_minor": 6
40+
"metadata": { ... }
41+
"cells": [ ... ]
42+
}
43+
```
44+
45+
It is REQUIRED that the top-level `$schema` be a canonical URI that refers to the Jupyter Notebook formats, i.e. `$schema` cannot be an arbitrary URI to a valid notebook schema, but instead must be useable as a token that uniquely identifies that schema, e.g.:
46+
47+
Valid `$schema` URI:
48+
49+
```json
50+
{
51+
"$schema": "https://jupyter.org/schema/notebook/4.6/notebook-4.6.schema.json"
52+
...
53+
}
54+
```
55+
56+
Invalid `$schema` URI:
57+
58+
```json
59+
{
60+
"$schema": "https://jupyter.org/schema/../schema/notebook/4.6/notebook-4.6.schema.json"
61+
...
62+
}
63+
```
64+
65+
# Reference-level explanation
66+
67+
JSON Schema changes:
68+
69+
```
70+
{
71+
"$schema": "http://json-schema.org/draft-04/schema#",
72+
"description": "Jupyter Notebook v4.5 JSON schema.",
73+
"type": "object",
74+
"additionalProperties": false,
75+
"required": ["$schema", "nbformat", "nbformat_minor", metadata", "cells"], // CHANGED
76+
"properties": {
77+
"$schema": {
78+
"description": "JSON schema the notebook should adhere to",
79+
"type": "string"
80+
}
81+
"metadata": { <no changes > }
82+
"nbformat_minor": {
83+
"description": "Notebook format (minor number). Incremented for backward compatible changes to the notebook format.",
84+
"type": "integer",
85+
"minimum": 6,
86+
"deprecated": true // CHANGED
87+
},
88+
"nbformat": {
89+
"description": "Notebook format (major number). Incremented between backwards incompatible changes to the notebook format.",
90+
"type": "integer",
91+
"minimum": 4,
92+
"maximum": 4
93+
"deprecated": true // CHANGED
94+
},
95+
"cells": [ <no changes> ]
96+
},
97+
"definitions": { <no changes> }
98+
}
99+
```
100+
101+
# Rationale and alternatives
102+
103+
Not doing this will leave the Jupyter notebook format in a non-standard state.
104+
105+
# Prior art
106+
107+
[JSON Schema](https://json-schema.org/) is a widely adopted declarative language that annotates and validates documents, so it's the obvious candidate to adhere to.
108+
109+
# Unresolved questions
110+
111+
- Code to upgrade from and downgrade to 4.5 still needs to be written.
112+
Some exploration has been done by Nick Bollweg in [this gist](https://gist.github.com/bollwyvl/a6e1ae13125f01ff04edf121e30a462a).
113+
- We want to deprecate `nbformat` and `nbformat_minor` in favor of `$schema` but we also need to ensure old clients can still work with notebooks in this new schema, so `nbformat` and `nbformat_minor` are still required. What's the path here? Major version update?
114+
115+
# Future possibilities
116+
117+
This work paves the way for [``Add `extraSchemas` to notebook format`` JEP](https://hackmd.io/9QZ8YibfQHm9l1B6JPSQsg?both), which will be submitted as a separate JEP soon.

0 commit comments

Comments
 (0)