y-py: Python bindings for Y-CRDT

0.6.2 · active · verified Sat Apr 11

y-py is a high-performance Python binding for Y-CRDT, a distributed data type library built in Rust. It enables seamless real-time synchronization of state between processes and cross-domain communication with other Y-CRDT bindings like Y-Wasm. The project is currently experimental, with API changes expected before a 1.0 stable release. The current stable version is 0.6.2.

Warnings

Install

Imports

Quickstart

This example demonstrates how to create a YDoc, modify its content within a transaction, and synchronize changes between two document instances.

import y_py as Y

d1 = Y.YDoc()
text = d1.get_text('test')

with d1.begin_transaction() as txn:
    text.extend(txn, "hello world!")

d2 = Y.YDoc()
state_vector = Y.encode_state_vector(d2)
diff = Y.encode_state_as_update(d1, state_vector)
Y.apply_update(d2, diff)

value = str(d2.get_text('test'))
assert value == "hello world!"
print(f"Synchronized text: {value}")

view raw JSON →