Socket
Socket
Sign inDemoInstall

@jupyterlab/nbformat

Package Overview
Dependencies
Maintainers
10
Versions
270
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jupyterlab/nbformat

Notebook format interfaces


Version published
Weekly downloads
125K
increased by9.19%
Maintainers
10
Weekly downloads
 
Created

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

FAQs

Package last updated on 26 Feb 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc