Skip to main content

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.

Installation

For development installation with test dependencies:

pip install -e ".[dev]"

Tests

First run a y-sweet server:

npx y-sweet serve

Then run the tests:

pytest

Development

Run ruff format to format before committing changes.

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.6.3.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

y_sweet_sdk-0.6.3-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file y_sweet_sdk-0.6.3.tar.gz.

File metadata

  • Download URL: y_sweet_sdk-0.6.3.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for y_sweet_sdk-0.6.3.tar.gz
Algorithm Hash digest
SHA256 fb82476fd919fa336b5dc260d80f54b1c5b888b49150991aab15399c02f368b6
MD5 b2f7153a2c7e6662d9005ae3864a246a
BLAKE2b-256 fc3b7dea3261416094da942b548ad972d144829c06c06a7f211a4985c01a46ab

See more details on using hashes here.

File details

Details for the file y_sweet_sdk-0.6.3-py3-none-any.whl.

File metadata

  • Download URL: y_sweet_sdk-0.6.3-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for y_sweet_sdk-0.6.3-py3-none-any.whl
Algorithm Hash digest
SHA256 9fffa366291725c43d134690c8ee1a214ee86c2aa3a42a7a6c63e8e00519280d
MD5 ef6f9f847068a71744b161bed0329bf2
BLAKE2b-256 38963fd2d39f2c895233b2efd9a53e3a5b0809f412169a74aad9de8e3cc6e731

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page