jupyter / jupyter/nbformat

Appending cell to the existed notebook

Open
#176 4 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
313
Forks
176
PR merge metrics
No merged PRs in 30d

Description

The `nbf.write()` seems working pretty good with new notebook generation.
```
import nbformat as nbf
nb = nbf.v4.new_notebook()

text = """\
# Manual EDA with automatic notebook genration"""

code = """\
%pylab inline
hist(normal(size=2000), bins=50);"""

nb['cells'] = [nbf.v4.new_markdown_cell(text),
nbf.v4.new_code_cell(code)
]

with open('test.ipynb', 'a') as f:
nbf.write(nb, f)
```

But I couldn't find the same smooth method in `nbformat` to append cells to existed notebook.
Is there a simpler way to that?

```
import json
with open('eda.ipynb', 'r') as f:
json_obj = json.load(f)

# concat cells
json_obj['cells'] = json_obj['cells'] + nb['cells']

with open('test.ipynb', 'w') as f:
json.dump(json_obj, f)
```

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the nbformat read and write APIs, especially the nbf.write() entry point and how notebook cells are represented. Determine whether appending cells to an existing .ipynb file can be supported through a public API rather than manual JSON handling. Done means the supported approach preserves the existing notebook and adds the new cells.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, python
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.