ypy-websocket 0.9.0
pip install ypy-websocket==0.9.0
Newer version available (0.12.4)
Released:
WebSocket connector for Ypy
Navigation
Verified details
These details have been verified by PyPIMaintainers
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: MIT License (MIT License Copyright (c) 2022 David Brochart Permission is hereby granted, free of charge, to any...)
- Author: David Brochart
- Tags websocket, yjs
- Requires: Python >=3.7
Classifiers
- Development Status
- Intended Audience
- License
- Programming Language
Project description
ypy-websocket
ypy-websocket is an async WebSocket connector for Ypy.
Usage
Client
Here is a code example:
import asyncio
import y_py as Y
from websockets import connect
from ypy_websocket import WebsocketProvider
async def client():
ydoc = Y.YDoc()
async with connect("ws://localhost:1234/my-roomname") as websocket:
WebsocketProvider(ydoc, websocket)
ymap = ydoc.get_map("map")
with ydoc.begin_transaction() as t:
ymap.set(t, "key", "value")
asyncio.run(client())
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())
WebSocket API
The WebSocket object passed to WebsocketProvider
and WebsocketServer.serve
must respect the
following API:
class WebSocket:
@property
def path(self) -> str:
# can be e.g. the URL path
# or a room identifier
return "my-roomname"
def __aiter__(self):
return self
async def __anext__(self) -> bytes:
# async iterator for receiving messages
# until the connection is closed
try:
message = await self.recv()
except:
raise StopAsyncIteration()
return message
async def send(self, message: bytes):
# send message
pass
async def recv(self) -> bytes:
# receive message
return b""
Project details
Verified details
These details have been verified by PyPIMaintainers
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: MIT License (MIT License Copyright (c) 2022 David Brochart Permission is hereby granted, free of charge, to any...)
- Author: David Brochart
- Tags websocket, yjs
- Requires: Python >=3.7
Classifiers
- Development Status
- Intended Audience
- License
- Programming Language
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
Built Distribution
File details
Details for the file ypy_websocket-0.9.0.tar.gz
.
File metadata
- Download URL: ypy_websocket-0.9.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd12ae046ea7ddf2c58f028b74cacb9c493dd07229c5efda775dcdc2c26096a5 |
|
MD5 | 81b05108ce65ab2a012b8fb7a95754fb |
|
BLAKE2b-256 | ad26927616d09366d016252ce20b00e5888ab14e1af94609ddc0f2289907d98d |
File details
Details for the file ypy_websocket-0.9.0-py3-none-any.whl
.
File metadata
- Download URL: ypy_websocket-0.9.0-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 22be32ca1ba8853f40192560556e110d1426a7156c37d436a2a46628f1389f7c |
|
MD5 | 9d07f1889d3366aa80074aa6d9f11538 |
|
BLAKE2b-256 | 52d9aba3f5e644b15f1d78359b5f7e4e254812433c2c4ca510aaa4fd543d2bae |