WebSocket connector for Ypy
Project description
ypy-websocket
ypy-websocket is an async WebSocket connector for Ypy.
Usage
Client
Here is a code example:
import asyncio
from websockets import connect
from ypy_websocket import YDoc, WebsocketProvider
async def client():
ydoc = YDoc()
websocket = await connect("ws://localhost:1234/my-roomname")
WebsocketProvider(ydoc, websocket)
ymap = ydoc.get_map("map")
with ydoc.begin_transaction() as t:
ymap.set(t, "key", "value")
asyncio.run(client())
Note that YDoc
has to be imported from ypy_websocket
instead of y_py
. This will change in the
future, when y_py
has the necessary event handlers. ypy_websocket.YDoc
is a subclass of
y_py.YDoc
.
Server
Here is a code example:
import asyncio
from websockets import serve
from ypy_websocket import WebsocketServer
async def server():
websocket_server = WebsocketServer()
async with serve(websocket_server.serve, "localhost", 1234):
await asyncio.Future() # run forever
asyncio.run(server())
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
ypy_websocket-0.1.5.tar.gz
(4.8 kB
view details)
Built Distribution
File details
Details for the file ypy_websocket-0.1.5.tar.gz
.
File metadata
- Download URL: ypy_websocket-0.1.5.tar.gz
- Upload date:
- Size: 4.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1aee9a5c483d306e5ba5d7ccab3c9412264d4ee681fd2e456071f82dac1a0a6 |
|
MD5 | 62dacaa86050126cdd552cd0de1e1d3b |
|
BLAKE2b-256 | a13f278675bfc9927cde67f10805c706749ead0919d9076036194c9218541fae |
Provenance
File details
Details for the file ypy_websocket-0.1.5-py2.py3-none-any.whl
.
File metadata
- Download URL: ypy_websocket-0.1.5-py2.py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 404efa85ce7d5340515416e5b52152610fb36204434076f99e2bf44f34355760 |
|
MD5 | f5c088b8a5a967b55faf7228482166c4 |
|
BLAKE2b-256 | 00c8cfb4dc4eae5adb50288e2c870a192ae3b20b508f914dae32b09065cf4a4a |