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.1.tar.gz
(4.5 kB
view hashes)
Built Distribution
Close
Hashes for ypy_websocket-0.1.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c2cf06dce9ae25456af16e11efecfd6b2b110a1cfe72d58a0f695025180e8efb |
|
MD5 | 5af84f086f467119e3061f7d7662f18e |
|
BLAKE2b-256 | dda539f5494b8c3b506a393e44e23654038ab2aa3c58299daec508fdab6a5484 |