Python bindings for the Y-Sweet server
Project description
y_sweet_sdk
Usage
from y_sweet_sdk import DocumentManager
# Get the websocket url for a document.
doc = DocumentManager('ys://localhost:8080')
url = doc.get_websocket_url('my-document-id')
# Connect to the document using y_py and ypy_websocket.
# (Based on: https://davidbrochart.github.io/ypy-websocket/usage/client/)
from ypy_websocket import WebsocketProvider
import y_py as Y
from websockets import connect
import asyncio
ydoc = Y.YDoc()
# Simple example: log the array "todolist" to stdout every time it changes.
data = ydoc.get_array("todolist")
def data_changed(event: Y.AfterTransactionEvent):
print(f"data changed: {data.to_json()}")
data.observe_deep(data_changed)
async with (
connect(url) as websocket,
WebsocketProvider(ydoc, websocket),
):
await asyncio.Future() # run forever
y_sweet_sdk
is only used to talk directly with the Y-Sweet server to obtain a WebSocket URL to pass to a client.
Use a Yjs client like ypy-websocket or pycrdt
in conjunction with y_sweet_sdk
to access the actual Y.Doc data.
Tests
First run a y-sweet server:
npx y-sweet serve
Then run the tests:
python -m unittest discover -s tests
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
y_sweet_sdk-0.1.0.tar.gz
(3.7 kB
view hashes)
Built Distribution
Close
Hashes for y_sweet_sdk-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1345604bf0aaf83681dc08c2f6f944e8115961117b5656ce19a9ba2b0e4a55e7 |
|
MD5 | ee39da05b7083f9685ce8138da0d0e17 |
|
BLAKE2b-256 | 523df0da9bda3fc20f98ee265347a543aea043dda92abc485dc96c74cc7023ab |