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.

Developing

Developing y_sweet_sdk requires the uv project manager.

To install it on Mac or Liunux, run:

curl -LsSf https://astral.sh/uv/install.sh | sh

(See the docs for other platforms and more information.)

When using uv, you do not need to manage a virtual environment yourself. Instead, you interact with Python using the uv command, which automatically picks up the virtual environment from the location.

To set up the virtual environment for development, run:

uv sync --dev

This installs both the regular dependencies and the development dependencies.

Tests

Once commands are installed in your virtual environment, you can run them with uv run.

To run tests, run:

uv run pytest

This runs the pytest command in the virtual environment.

Formatting

Run uv 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.4.tar.gz (5.5 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.4-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for y_sweet_sdk-0.6.4.tar.gz
Algorithm Hash digest
SHA256 af8b952a0cdfa821ba4b37c6e292a773ca2968420750774fbeba11a502b9e1b4
MD5 89523f6ce5856d4f342c1fe7c1dae8ac
BLAKE2b-256 eb1b2d507691b9f26248651252c51f6caad0cbe0f9bcd73d5216b4f80e745a84

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for y_sweet_sdk-0.6.4-py3-none-any.whl
Algorithm Hash digest
SHA256 43dcc9920330b3bc7fc9734daac94e9ae538ab0557edb1985ede9b530259db48
MD5 c589ae01ccc1ee19daeeb90d6fb886b2
BLAKE2b-256 402f159b5f4effbd37badbd94d9e552ba991268351ed6b999d7bef302fef1c61

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