What is @jupyterlab/nbformat?
@jupyterlab/nbformat is an npm package that provides utilities for working with Jupyter Notebook files. It allows you to read, write, and manipulate notebook files in JSON format, making it easier to integrate Jupyter Notebooks into JavaScript/TypeScript applications.
What are @jupyterlab/nbformat's main functionalities?
Reading a Notebook
This feature allows you to read a Jupyter Notebook file from the filesystem and parse its JSON content. The code sample demonstrates how to read a notebook file named 'example.ipynb' and parse its content into a JavaScript object.
const nbformat = require('@jupyterlab/nbformat');
const fs = require('fs');
const notebookContent = fs.readFileSync('example.ipynb', 'utf8');
const notebook = JSON.parse(notebookContent);
console.log(notebook);
Writing a Notebook
This feature allows you to create a new Jupyter Notebook file and write it to the filesystem. The code sample demonstrates how to create a basic notebook object and write it to a file named 'new_notebook.ipynb'.
const nbformat = require('@jupyterlab/nbformat');
const fs = require('fs');
const notebook = {
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
};
const notebookContent = JSON.stringify(notebook, null, 2);
fs.writeFileSync('new_notebook.ipynb', notebookContent);
Manipulating Notebook Cells
This feature allows you to manipulate the cells within a Jupyter Notebook. The code sample demonstrates how to add a new code cell to an existing notebook and save the updated notebook back to the filesystem.
const nbformat = require('@jupyterlab/nbformat');
const fs = require('fs');
const notebookContent = fs.readFileSync('example.ipynb', 'utf8');
const notebook = JSON.parse(notebookContent);
// Add a new code cell
const newCell = {
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": ["print('Hello, world!')"]
};
notebook.cells.push(newCell);
const updatedContent = JSON.stringify(notebook, null, 2);
fs.writeFileSync('example.ipynb', updatedContent);
Other packages similar to @jupyterlab/nbformat
nbformat
The 'nbformat' package is a Python library for reading and writing Jupyter Notebook files. It provides similar functionalities to @jupyterlab/nbformat but is intended for use in Python environments. It is part of the Jupyter project and is widely used in the Jupyter ecosystem.
notebookjs
The 'notebookjs' package is a JavaScript library for converting Jupyter Notebooks to HTML. While it focuses on rendering notebooks as HTML, it also provides utilities for reading and parsing notebook files. It is useful for web applications that need to display notebook content.
nbconvert
The 'nbconvert' package is a Python library for converting Jupyter Notebooks to various formats, including HTML, PDF, and Markdown. It provides more advanced conversion capabilities compared to @jupyterlab/nbformat, but it is primarily intended for use in Python environments.
v2.1.0
April 2020
See the JupyterLab
2.1
milestone on GitHub for the full list of pull requests and issues
closed.
User-facing changes
- Display the extension manager in the left sidebar by default. Users
will need to acknowledge the disclaimer in the extension manager
before using it.
(#8050,
#8145)
- Added
blacklist and whitelist support <extension_listings>
for the
extension manager
(#7989) - Automatically link URLs in notebook output text
(#8075,
#7393)
- Added a "Restart Kernel and Run All Cells..." button to the
notebook toolbar
(#8024)
<img alt="The main JupyterLab toolbar with focus on the Restart Kernel and Run All Cells button." src="https://raw.githubusercontent.com/jupyterlab/jupyterlab/3.1.x/docs/source/getting_started/changelog_restartrunallbutton.png" class="jp-screenshot">
-
Added a context menu item for opening a Markdown editor from the
Markdown preview
(#7942)
-
Support Node.js 10+
(#8112,
#8083)
-
Added a command to replace the selection in an editor with text
(inserting if there is no selection). This can be assigned a
keyboard shortcut, as shown below. We also added a command to go
through a series of commands and run the first enabled command.
(#7908) Here
is a keyboard shortcut to insert text in a currently-active notebook
editor:
{
command: "notebook:replace-selection",
selector: ".jp-Notebook",
keys: ["Ctrl L"],
args: {text: "lambda x: x"}
}
Here is a keyboard shortcut to insert text into an editor of the
currently active console, file editor, or notebook:
{
command: "apputils:run-first-enabled",
selector: "body",
keys: ["Ctrl L"],
args: {
commands: [
"console:replace-selection",
"fileeditor:replace-selection",
"notebook:replace-selection",
],
args: {text: "lambda x: x"}
}
}
For developers
NotebookWidgetFactory
is now a plugin so it can be overridden
(#8066,
#7996)- Many improvements to
LabIcon
: work with all SVG loaders, improve
performance, fix issue with menus from extensions
(#8125) - Change the header application area to a box panel, which means the
header area will display if its children set their minimum height
(#8059,
#7279)
- JupyterLab's custom context menu is now disabled on all descendants
of a DOM element with a
data-jp-suppress-context-menu
attribute
(#7877,
#7670)
Bugfixes
- Fix property inspector restoration on reload
(#8114)
- Increase the timeout for yarn
(#8104,
#8102)
- Fix find and replace with empty strings
(#8100,
#8098)
- Select search text when focusing the search overlay
(#8073,
#7932)
- Fix attaching images with spaces in their names to Markdown cells
(#8095)
- Fix build errors by distributing the
.yarnrc
configuration with
the Python package
(#8045) - Throttle fetch requests in the setting registry's data connector
(#7927)
- Close the gap between lines in notebook output
(#7832,
#7760)