{"id":2680,"library":"pycrdt","title":"PyCRDT","description":"Pycrdt is a Python library providing bindings for Yrs, the Rust port of the Yjs framework. It enables the creation of Conflict-free Replicated Data Types (CRDTs), allowing shared documents to automatically merge concurrent changes from different replicas, ensuring eventual consistency. The library is actively maintained, with frequent releases, and is currently at version 0.12.50.","status":"active","version":"0.12.50","language":"en","source_language":"en","source_url":"https://github.com/y-crdt/pycrdt","tags":["CRDT","realtime","sync","Yjs","Yrs","collaboration"],"install":[{"cmd":"pip install pycrdt","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"note":"The primary class for creating and managing a shared document.","symbol":"Doc","correct":"from pycrdt import Doc"},{"note":"A CRDT type similar to a string, for collaborative text editing.","symbol":"Text","correct":"from pycrdt import Text"},{"note":"A CRDT type similar to a list, for collaborative array manipulation.","symbol":"Array","correct":"from pycrdt import Array"},{"note":"A CRDT type similar to a dictionary, for collaborative key-value storage.","symbol":"Map","correct":"from pycrdt import Map"}],"quickstart":{"code":"from pycrdt import Doc, Text, Array, Map\n\n# Create a shared document\ndoc0 = Doc()\n\n# Get or create root types for collaborative data\ntext0 = doc0.get(\"text\", type=Text)\narray0 = doc0.get(\"array\", type=Array)\nmap0 = doc0.get(\"map\", type=Map)\n\n# Make changes to the document within a transaction\nwith doc0.transaction():\n    text0.insert(0, \"hello\")\n    array0.append()\n    map0[\"key1\"] = \"value1\"\n\n# Get the updates from doc0\nupdates = doc0.get_update()\n\n# Simulate another client or replica\ndoc1 = Doc()\n\n# Apply updates from doc0 to doc1\ndoc1.apply_update(updates)\n\n# Verify the state of doc1\ntext1 = doc1.get(\"text\", type=Text)\narray1 = doc1.get(\"array\", type=Array)\nmap1 = doc1.get(\"map\", type=Map)\n\nprint(f\"Doc1 Text: {text1}\")\nprint(f\"Doc1 Array: {array1}\")\nprint(f\"Doc1 Map: {map1}\")\n\n# Make further changes on doc1 concurrently\nwith doc1.transaction():\n    text1.insert(5, \" world\")\n    array1.append()\n    map1[\"key2\"] = \"value2\"\n\n# Get updates from doc1, relative to doc0's initial state for merging\nupdates_from_doc1 = doc1.get_update(doc0.get_state())\n\n# Apply updates from doc1 back to doc0\ndoc0.apply_update(updates_from_doc1)\n\n# Verify doc0 has the merged state\nprint(f\"Doc0 Text (merged): {doc0.get('text', type=Text)}\")\nprint(f\"Doc0 Array (merged): {doc0.get('array', type=Array)}\")\nprint(f\"Doc0 Map (merged): {doc0.get('map', type=Map)}\")","lang":"python","description":"This quickstart demonstrates how to initialize a `pycrdt.Doc`, interact with its shared data types (`Text`, `Array`, `Map`), and synchronize changes between two document replicas by exchanging updates."},"warnings":[{"fix":"Upgrade to Python 3.10 or newer.","message":"Python 3.9 support was dropped in version 0.12.37.","severity":"breaking","affected_versions":"0.12.37 and later"},{"fix":"Switch to a CPython environment or use an older `pycrdt` version if PyPy 3.10 is required. Python 3.10+ CPython is recommended.","message":"PyPy 3.10 support was dropped in version 0.12.41.","severity":"breaking","affected_versions":"0.12.41 and later"},{"fix":"Ensure you are using `pycrdt` version 0.12.50 or newer for robust concurrent async transaction handling.","message":"Prior to version 0.12.50, there could be issues with concurrent async transactions that might lead to unexpected behavior.","severity":"gotcha","affected_versions":"<0.12.50"},{"fix":"Upgrade to `pycrdt` 0.12.48 or later. If using tuples, ensure they are converted to lists before assignment if compatibility with older versions or other Yjs clients is critical for that specific data type.","message":"Before version 0.12.48, tuples assigned to `Map` entries were incorrectly handled and converted to 'undefined' in the underlying Yrs structure.","severity":"gotcha","affected_versions":"<0.12.48"},{"fix":"Update to `pycrdt` 0.12.45 or newer, which now collects all exceptions from observer callbacks into an `ExceptionGroup` for more resilient error handling.","message":"Prior to version 0.12.45, exceptions raised within observer callbacks (e.g., `observe`, `observe_deep`) were not grouped. A single exception could halt further callback execution.","severity":"gotcha","affected_versions":"<0.12.45"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}