Introduction
An .ipynb file is a Jupyter notebook: a document made of cells, some
holding code and some holding text, with the output of each code cell saved beside it.
The name comes from IPython, the project Jupyter grew out of. Notebooks are mostly used
with Python, but a notebook can use any language that has a Jupyter kernel.
Structure
A notebook is a JSON document. The top level has four keys: nbformat and
nbformat_minor, the format version (4 for current notebooks),
metadata, which names the kernel and language, and cells, the
list of cells in order.
Each cell has a cell_type of code, markdown or
raw, its source text and its own metadata. Code cells also keep
an execution_count and a list of outputs: printed text, results,
errors, and rich output such as images, which are stored base64-encoded inside the
JSON. Every key, cell and output type is on the
notebook format page.
{
"nbformat": 4,
"nbformat_minor": 5,
"metadata": {
"kernelspec": { "name": "python3", "display_name": "Python 3", "language": "python" }
},
"cells": [
{ "cell_type": "markdown", "id": "a1", "metadata": {}, "source": ["# Sums"] },
{ "cell_type": "code", "id": "b2", "metadata": {}, "execution_count": 1,
"source": ["1 + 1"],
"outputs": [ { "output_type": "execute_result", "execution_count": 1,
"data": { "text/plain": ["2"] }, "metadata": {} } ] }
]
}
Not described
Known, not yet covered
- Viewer: the viewer shows the JSON tree with every cell, output, MIME value and metadata key labelled, the cells, outputs and MIME bundles as paged tables (pictures, HTML, Markdown and JSON open as files), the metadata keys, the notebook as a Markdown document, and the nbformat checks for versions 4.0 to 4.5 and 3 with the exact path of each problem. What it does not do yet: draw the pictures, rendered HTML or widgets inside a cell (a picture opens as its own file), and render a code cell’s output as the notebook would; widget state is listed, not interpreted; the nbformat 1 and 2 checks only name unknown cell and output types, because those versions have no schema; and it does not check a
+jsonor vendor MIME type’s own content.
- Reference: (non-blocking) the writer of
vscode.interpreter.hashin VS Code’s notebook metadata was not located; the nbformat page gives the hash function vscode-jupyter uses for interpreters (SHA-256, lower-case hex) and says so. - Reference: the v3 to v4 and v4 to v3 conversion rules are described on the page as nbformat library behaviour, not as part of the format, pending the owner’s ruling on whether they belong.
Unknown
- Reference: Google Colab’s notebook metadata (the
colabkey and cell keys such asidandcolab_type): no public raw documentation or source from the Colab project defining the keys was found, so the page does not describe them.
Links
Software
- JupyterLab and Jupyter Notebook – the Jupyter project’s own notebook editors, run locally or on a server (any browser)
- Visual Studio Code – code editor that opens and runs notebooks (Windows, macOS, Linux)
- Google Colab – Google’s hosted notebooks, which open and save .ipynb (web)
- PyCharm – JetBrains’ Python IDE, with notebook support (Windows, macOS, Linux)
- nbviewer – shows a notebook online as a web page (web)
- GitHub and GitLab – show notebooks in the browser (web)
Developers
Reference
- The Jupyter Notebook Format – the format’s documentation and JSON schema