{"id":9211,"library":"pycrdt-websocket","title":"Pycrdt WebSocket Connector","description":"Pycrdt-websocket provides a WebSocket connector for `pycrdt`, enabling real-time, collaborative document synchronization using Y-CRDTs over a network. It facilitates both server-side handling of Y-CRDT documents and client-side connections. The library is actively maintained with frequent minor releases, typically addressing bug fixes and compatibility updates.","status":"active","version":"0.16.0","language":"en","source_language":"en","source_url":"https://github.com/y-crdt/pycrdt-websocket","tags":["websocket","crdt","y-crdt","real-time","collaboration","sync","asyncio"],"install":[{"cmd":"pip install pycrdt-websocket","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core Y-CRDT implementation; pycrdt-websocket relies on it for document synchronization.","package":"pycrdt","optional":false},{"reason":"Provides the abstract YStore base class and related utilities, extracted in v0.16.0. Required if you need to manage Y documents in a store.","package":"pycrdt-store","optional":false},{"reason":"Used for the underlying WebSocket communication; typically installed as a transitive dependency.","package":"websockets","optional":false}],"imports":[{"note":"Package name changed from `pycrdt_websocket` to `pycrdt.websocket` in v0.16.0.","wrong":"from pycrdt_websocket import WebSocketServer","symbol":"WebSocketServer","correct":"from pycrdt.websocket import WebSocketServer"},{"note":"Package name changed from `pycrdt_websocket` to `pycrdt.websocket` in v0.16.0.","wrong":"from pycrdt_websocket import YDocRoom","symbol":"YDocRoom","correct":"from pycrdt.websocket import YDocRoom"},{"note":"The YStore class was extracted into the `pycrdt-store` package starting from v0.16.0.","wrong":"from pycrdt.websocket import YStore","symbol":"YStore","correct":"from pycrdt_store import YStore"}],"quickstart":{"code":"import asyncio\nfrom pycrdt import YDoc, YText\nfrom pycrdt.websocket import WebSocketServer, YDocRoom\n\nasync def server_main():\n    # Initialize a Y-CRDT document for the server\n    ydoc = YDoc()\n    with ydoc.transaction():\n        text = ydoc.get_text('my_text')\n        text += 'Hello from server!'\n\n    # Create a WebSocket server that manages rooms\n    server = WebSocketServer(ydoc, 'ws://127.0.0.1:1234')\n    print(\"Server starting on ws://127.0.0.1:1234\")\n    await server.start()\n    await asyncio.sleep(5) # Keep server running for a bit\n    await server.stop()\n    print(\"Server stopped\")\n\nasync def client_main():\n    await asyncio.sleep(1) # Give server a moment to start\n    print(\"Client connecting...\")\n    # Connect to the server with a YDocRoom\n    client_ydoc = YDoc()\n    room = YDocRoom(client_ydoc, 'ws://127.0.0.1:1234')\n    await room.connect()\n\n    # Access the shared text\n    shared_text = client_ydoc.get_text('my_text')\n    print(f\"Client received: '{shared_text}'\")\n\n    with client_ydoc.transaction():\n        shared_text.append(' And client!')\n    print(f\"Client sent: '{shared_text}'\")\n\n    await asyncio.sleep(1) # Allow changes to propagate\n    await room.disconnect()\n    print(\"Client disconnected\")\n\nasync def main():\n    server_task = asyncio.create_task(server_main())\n    client_task = asyncio.create_task(client_main())\n    await asyncio.gather(server_task, client_task)\n\nif __name__ == '__main__':\n    asyncio.run(main())\n","lang":"python","description":"This quickstart demonstrates a basic pycrdt-websocket setup with a server and a client. The server initializes a YDoc and listens for connections, while the client connects to synchronize its own YDoc. It shows how text changes are synchronized in real-time."},"warnings":[{"fix":"Replace `from pycrdt_websocket import ...` with `from pycrdt.websocket import ...`.","message":"The top-level package name for imports changed from `pycrdt_websocket` to `pycrdt.websocket` starting from version 0.16.0. This requires updating all import statements.","severity":"breaking","affected_versions":">=0.16.0"},{"fix":"Install `pycrdt-store` (`pip install pycrdt-store`) and update imports from `from pycrdt.websocket import YStore` to `from pycrdt_store import YStore`.","message":"The `YStore` class, which manages persistence for Y-CRDT documents, was extracted into a separate package `pycrdt-store` starting from version 0.16.0. If you were using or subclassing `YStore` directly, you now need to import it from `pycrdt_store`.","severity":"breaking","affected_versions":">=0.16.0"},{"fix":"Ensure all calls to asynchronous methods are prefixed with `await` and run within an `async` function, typically managed by `asyncio.run()`.","message":"Pycrdt-websocket is built on `asyncio` and requires `await` for all network operations (e.g., `server.start()`, `room.connect()`). Forgetting `await` will lead to silent failures or incorrect behavior.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the `pycrdt-websocket` project's `pyproject.toml` or `setup.py` for the exact `pycrdt` version range requirement, and upgrade/downgrade `pycrdt` accordingly (e.g., `pip install pycrdt>=0.9.0,<0.11.0`).","message":"Compatibility with `pycrdt` versions is crucial. Always check the release notes for `pycrdt-websocket` to ensure you are using a compatible `pycrdt` version, as internal API changes in `pycrdt` can break `pycrdt-websocket` functionality.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Update your import statements to use `from pycrdt.websocket import ...`.","cause":"Attempting to import from the old package name `pycrdt_websocket` after upgrading to version 0.16.0 or newer.","error":"ModuleNotFoundError: No module named 'pycrdt_websocket'"},{"fix":"Install `pycrdt-store` (`pip install pycrdt-store`) and change your import to `from pycrdt_store import YStore`.","cause":"`YStore` was moved to the `pycrdt-store` package in version 0.16.0, and is no longer directly available from `pycrdt.websocket`.","error":"AttributeError: module 'pycrdt.websocket' has no attribute 'YStore'"},{"fix":"Ensure that `room.connect()` (and similar `async` methods) are called with `await` inside an `async def` function, and that the top-level call is handled by `asyncio.run()`.","cause":"You are attempting to use an `async` function call (like `room.connect()`) without the `await` keyword, or calling it outside an `async` context.","error":"TypeError: object Room can't be used in 'await' expression"}]}