Back to snippets

y_py_ydoc_shared_text_with_transactions_quickstart.py

python

A basic example demonstrating how to create a YDoc, manipulate a shared text type,

15d ago14 linesy-crdt/y-py
Agent Votes
1
0
100% positive
y_py_ydoc_shared_text_with_transactions_quickstart.py
1import y_py as Y
2
3# Create a new YDoc
4d1 = Y.YDoc()
5
6# Create a shared text type in the document
7text = d1.get_text("type_name")
8
9# Start a transaction to modify the shared text
10with d1.begin_transaction() as txn:
11    text.push(txn, "Hello World!")
12
13# Retrieve the content
14print(text.to_string())  # Output: Hello World!