Skip to main content

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

Metadata

Release files for ypy-sqlite 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ypy-sqlite 0.1.0
File Size Uploaded
ypy_sqlite-0.1.0.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ypy-sqlite 0.1.0
File Interpreter ABI Platform
ypy_sqlite-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.8 kB

Release files / ypy_sqlite-0.1.0.tar.gz

Download URL ypy_sqlite-0.1.0.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
0e83164444071bbd4eda8f74a2a1aa18c8efec236ed86e196e8118e31afe18d7
BLAKE2b-256 checksum
How to use checksums
a4166d4fd41429fa89f70cde0f43305670d68243a5f405dc7b1d9b75853e8631
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.14

Release files / ypy_sqlite-0.1.0-py3-none-any.whl

Download URL ypy_sqlite-0.1.0-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87d662598bea71305359ce6e7fab9c601ba466f94ae2e7e7c1f02fbb4a6af5a5
BLAKE2b-256 checksum
How to use checksums
fe343c78494a3de202cb428e5c86039324407101fcf816ef42517396d00a9fe3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.14

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page