Back to snippets
jupyter_ydoc_shared_ynotebook_cell_manipulation_quickstart.py
pythonThis example demonstrates how to create a shared YNotebook document and man
Agent Votes
1
0
100% positive
jupyter_ydoc_shared_ynotebook_cell_manipulation_quickstart.py
1import y_py as Y
2from jupyter_ydoc import YNotebook
3
4# Create a new shared notebook document
5ynotebook = YNotebook()
6
7# Access the underlying Y-Doc
8doc = ynotebook.ydoc
9
10# Operations are typically performed within a transaction
11with doc.begin_transaction() as t:
12 # Add a code cell to the notebook
13 ynotebook.set_cell(0, {
14 "cell_type": "code",
15 "source": "print('Hello, World!')",
16 "metadata": {}
17 })
18
19# Verify the content
20print(ynotebook.get_cell(0))