Skip to main content

SQLite persistence provider for YPY (Python bindings for YJS)

Project description

YPY SQLite Persistence Provider

A SQLite persistence provider for YPY, the Python bindings for Yjs.

Installation

pip install ypy-sqlite

Usage

Here's a basic example of how to use the YPY SQLite persistence provider:

import asyncio
import y_py as Y
from ypy_sqlite import SQLitePersistence

async def example():
    # Initialize the persistence layer
    persistence = await SQLitePersistence.build("data.db", {
        "flush_size": 100,
        "table_name": "my_documents",
        "use_index": True
    })

    # Create and load a document
    doc_name = "example-doc"
    ydoc = await persistence.get_ydoc(doc_name)

    # Make changes
    with ydoc.begin_transaction() as txn:
        ytext = txn.get_text("content")
        ytext.insert(0, "Hello, world!")

    # Get updates for sync
    state_vector = await persistence.get_state_vector(doc_name)

    # Store updates
    update = Y.encode_state_as_update(ydoc)
    await persistence.store_update(doc_name, update)

    # Clean up
    await persistence.destroy()

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

API

SQLitePersistence

async SQLitePersistence.build(db_path, options=None)

Initialize the persistence layer with options.

  • db_path: Path to the SQLite database file
  • options: Configuration options
    • flush_size: Number of updates before flushing (default: 200)
    • table_name: Name of the table to store documents (default: "ypy_documents")
    • use_index: Whether to use an index on the table (default: True)

async get_ydoc(doc_name)

Create a Y.Doc instance with the data persisted in SQLite.

async store_update(doc_name, update)

Store a single document update to the database.

async get_state_vector(doc_name)

Get the state vector for a document.

async get_diff(doc_name, state_vector)

Get differences between the current document state and the provided state vector.

async clear_document(doc_name)

Delete a document and all associated data from the database.

async destroy()

Clean up resources and close the database connection.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ypy_sqlite-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ypy_sqlite-0.1.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file ypy_sqlite-0.1.0.tar.gz.

File metadata

  • Download URL: ypy_sqlite-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.14

File hashes

Hashes for ypy_sqlite-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0e83164444071bbd4eda8f74a2a1aa18c8efec236ed86e196e8118e31afe18d7
MD5 484a00819d9ef17542a56db39e43288d
BLAKE2b-256 a4166d4fd41429fa89f70cde0f43305670d68243a5f405dc7b1d9b75853e8631

See more details on using hashes here.

File details

Details for the file ypy_sqlite-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for ypy_sqlite-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 87d662598bea71305359ce6e7fab9c601ba466f94ae2e7e7c1f02fbb4a6af5a5
MD5 b0763e3f53f7e89a8d842912fe0eea34
BLAKE2b-256 fe343c78494a3de202cb428e5c86039324407101fcf816ef42517396d00a9fe3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page