Notebook Edit
Completely replaces the contents of a specific cell in a Jupyter notebook with support for insert and delete operations.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
Inputs
- Notebook Path -
string- Absolute path to the Jupyter notebook file (.ipynb) to edit (required). - New Source -
string- The new source code or markdown content for the cell (required). - Cell ID -
string- ID of the cell to edit; for insert mode, new cell will be inserted after this ID (optional). - Cell Type -
string- Type of the cell: "code" or "markdown" (optional, defaults to current type for replace, required for insert). - Edit Mode -
string- Edit operation: replace (default), insert, or delete (optional).
Options
None (all configuration through inputs).
Outputs
- Notebook Path -
string- Path to the edited notebook. - Cell ID -
string- ID of the affected cell (newly created ID for insert operations). - Edit Info -
object- Information about the edit operation:operation- Type of operation performed: create, replace, insert, deleteposition- Cell position in the notebookcellType- Type of cell affectedafterCell- Reference cell ID (for insert operations)error- Error message if operation failed
How It Works
The Notebook Edit node modifies Jupyter notebook cells. When executed, the node:
- Validates the notebook path is absolute and ends with .ipynb
- Reads and parses the existing notebook
- Performs the requested operation:
Replace Mode (default)
- If Cell ID provided: Finds and replaces that cell's content
- If no Cell ID: Creates new cell at the end
- Updates cell type if specified
- Clears outputs if changing to markdown
Insert Mode
- Creates new cell with generated ID
- If Cell ID provided: Inserts after that cell
- If no Cell ID: Inserts at beginning
- Sets cell type (defaults to "code")
Delete Mode
- Requires Cell ID
- Removes the specified cell
- Decrements position of all following cells
- Writes the modified notebook back to disk with proper formatting
- Returns the affected cell ID and operation details
Requirements
- Valid absolute path to .ipynb file
- File must be a valid Jupyter notebook
- Write permissions on the file
- Valid cell ID (required for delete mode)
- Non-empty new source (except for delete mode)
Error Handling
The node will return specific errors in the following cases:
- Missing notebook path - "Notebook path is required"
- Missing new source - "New source is required"
- Relative path - "Notebook path must be absolute"
- Wrong file extension - "File must be a Jupyter notebook (.ipynb)"
- File not found - "Notebook not found:
{{path}}" - Read error - "Failed to read notebook:
{{error}}" - Invalid format - "Invalid notebook format:
{{error}}" - Write error - "Failed to write notebook:
{{error}}" - Serialize error - "Failed to serialize notebook:
{{error}}"
Edit Info may contain errors for specific operations:
- Cell not found - "Cell with ID '
{{id}}' not found" - Delete without ID - "Cell ID is required for delete operation"
Usage Examples
Replace Cell Content
Notebook Path: /home/user/analysis.ipynb
Cell ID: abc123
New Source: import pandas as pd
df = pd.read_csv('new_data.csv')
df.head()
Edit Mode: replace
Insert New Code Cell
Notebook Path: /home/user/notebook.ipynb
Cell ID: xyz789
New Source: # New analysis section
print("Starting analysis...")
Cell Type: code
Edit Mode: insert
Insert Markdown Cell
Notebook Path: /home/user/docs.ipynb
New Source: # Chapter 1: Introduction
This notebook demonstrates...
Cell Type: markdown
Edit Mode: insert
Delete Cell
Notebook Path: /home/user/notebook.ipynb
Cell ID: old123
Edit Mode: delete
New Source: (ignored for delete)
Create Cell at End
Notebook Path: /home/user/notebook.ipynb
New Source: print("Final output")
Cell Type: code
Edit Mode: replace
(No Cell ID = append to end)
Change Cell Type
Notebook Path: /home/user/notebook.ipynb
Cell ID: abc123
New Source: # This is now markdown
Cell Type: markdown
Edit Mode: replace