PyCRDT Store

0.1.3 · active · verified Fri Apr 17

pycrdt-store provides persistent storage solutions for `pycrdt`, specifically offering a `SQLiteYStore` implementation. It enables `pycrdt` documents to persist their state beyond application lifetime, supporting features like history squashing, cleanup based on database size, and performance optimizations. The current version is 0.1.3, and the library is under active development with frequent minor releases addressing performance, features, and bug fixes.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up `SQLiteYStore` with a `pycrdt.YDoc` to enable persistent storage. It initializes an in-memory SQLite database, performs a simple text insertion, and then properly closes the store. For file-based persistence, replace `:memory:` with a file path like `./my_document.db`.

import asyncio
from pycrdt import YDoc
from pycrdt_store import SQLiteYStore

async def main():
    # Use an in-memory database for quick testing, or provide a file path
    # e.g., SQLiteYStore(path="./my_document.db")
    store = SQLiteYStore(path=":memory:")
    await store.setup() # Initialize the store connection

    doc_name = "my_persistent_doc"
    ydoc = YDoc(doc_name, store) # Associate YDoc with the store

    # Perform CRDT operations
    text = ydoc.get_text("my_text")
    text.insert(0, "Hello, world!")

    # Changes are automatically synchronized with the store by YDoc

    print(f"Document content: {text.to_py()}")

    await store.close() # Close the store connection

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →