-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Labels
enhancementNew feature or requestNew feature or request
Description
Problem
Currently the API supports getting the cell by index. Index is not a stable identifier in a notebook.
Proposed Solution
It would be perfect to be able to fetch a cell by ID, without the overhead of converting the entire notebook to Python objects
Additional context
jupyter_ydoc/jupyter_ydoc/ynotebook.py
Lines 92 to 115 in 9223523
def get_cell(self, index: int) -> Dict[str, Any]: | |
""" | |
Returns a cell. | |
:param index: The index of the cell. | |
:type index: int | |
:return: A cell. | |
:rtype: Dict[str, Any] | |
""" | |
meta = self._ymeta.to_py() | |
cell = self._ycells[index].to_py() | |
cell.pop("execution_state", None) | |
cast_all(cell, float, int) # cells coming from Yjs have e.g. execution_count as float | |
if "id" in cell and meta["nbformat"] == 4 and meta["nbformat_minor"] <= 4: | |
# strip cell IDs if we have notebook format 4.0-4.4 | |
del cell["id"] | |
if ( | |
"attachments" in cell | |
and cell["cell_type"] in ("raw", "markdown") | |
and not cell["attachments"] | |
): | |
del cell["attachments"] | |
return cell |
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request