Skip to main content

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.

Metadata

Release files for y-sweet-sdk 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for y-sweet-sdk 0.9.1
File Size Uploaded
y_sweet_sdk-0.9.1.tar.gz 5.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for y-sweet-sdk 0.9.1
File Interpreter ABI Platform
y_sweet_sdk-0.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.9 kB

Release files / y_sweet_sdk-0.9.1.tar.gz

Download URL y_sweet_sdk-0.9.1.tar.gz
Size 5.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cba138e62aaf4715b981f3f53b65850b27d33bbf4dde39155d4a88732ebff893
BLAKE2b-256 checksum
How to use checksums
401e330f29186ed1192da450b0f3842372be6267ea5bf21e8b93f4995c274153
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release files / y_sweet_sdk-0.9.1-py3-none-any.whl

Download URL y_sweet_sdk-0.9.1-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa2acbcc1d653db4a262b8934af9f5c75b594588fb9b0faa885572ed6fe575bb
BLAKE2b-256 checksum
How to use checksums
b1cb1646c0e22fbdd54d4e5c239d3b8be1741ec5796aeaafd830472b7e24c7b2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.11

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files

0.9.0

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.4

2 release files

0.6.3

2 release files

0.6.2

2 release files

0.6.1

2 release files

0.5.1

1 release file

0.5.0

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page