Python API#

class jupyter_ydoc.ybasedoc.YBaseDoc(ydoc: Doc | None = None)#

Base YDoc class. This class, defines the minimum API that any document must provide to be able to get and set the content of the document as well as subscribe to changes in the document.

property dirty: bool | None#

Returns whether the document is dirty.

Returns:

Whether the document is dirty.

Return type:

Optional[bool]

abstract get() Any#

Returns the content of the document.

Returns:

Document’s content.

Return type:

Any

abstract observe(callback: Callable[[str, Any], None]) None#

Subscribes to document changes.

Parameters:

callback (Callable[[str, Any], None]) – Callback that will be called when the document changes.

property path: str | None#

Returns document’s path.

Returns:

Document’s path.

Return type:

Optional[str]

abstract set(value: Any) None#

Sets the content of the document.

Parameters:

value (Any) – The content of the document.

property source: Any#

Returns the content of the document.

Returns:

The content of the document.

Return type:

Any

unobserve() None#

Unsubscribes to document changes.

This method removes all the callbacks.

abstract property version: str#

Returns the version of the document.

Returns:

Document’s version.

Return type:

str

property ydoc: Doc#

The underlying pycrdt.Doc that contains the data.

Returns:

The document’s ydoc.

Return type:

pycrdt.Doc

property ystate: Map#

A pycrdt.Map containing the state of the document.

Returns:

The document’s state.

Return type:

pycrdt.Map

class jupyter_ydoc.yblob.YBlob(ydoc: Doc | None = None)#

Extends YBaseDoc, and represents a blob document. The Y document is set from bytes.

Schema:

{
    "state": YMap,
    "source": YMap
}
property dirty: bool | None#

Returns whether the document is dirty.

Returns:

Whether the document is dirty.

Return type:

Optional[bool]

get() bytes#

Returns the content of the document.

Returns:

Document’s content.

Return type:

bytes

observe(callback: Callable[[str, Any], None]) None#

Subscribes to document changes.

Parameters:

callback (Callable[[str, Any], None]) – Callback that will be called when the document changes.

property path: str | None#

Returns document’s path.

Returns:

Document’s path.

Return type:

Optional[str]

set(value: bytes) None#

Sets the content of the document.

Parameters:

value (bytes) – The content of the document.

property source: Any#

Returns the content of the document.

Returns:

The content of the document.

Return type:

Any

unobserve() None#

Unsubscribes to document changes.

This method removes all the callbacks.

property version: str#

Returns the version of the document.

Returns:

Document’s version.

Return type:

str

property ydoc: Doc#

The underlying pycrdt.Doc that contains the data.

Returns:

The document’s ydoc.

Return type:

pycrdt.Doc

property ystate: Map#

A pycrdt.Map containing the state of the document.

Returns:

The document’s state.

Return type:

pycrdt.Map

class jupyter_ydoc.yfile.YFile(ydoc: Doc | None = None)#
property dirty: bool | None#

Returns whether the document is dirty.

Returns:

Whether the document is dirty.

Return type:

Optional[bool]

get() str#

Returns the content of the document.

Returns:

Document’s content.

Return type:

str

observe(callback: Callable[[str, Any], None]) None#

Subscribes to document changes.

Parameters:

callback (Callable[[str, Any], None]) – Callback that will be called when the document changes.

property path: str | None#

Returns document’s path.

Returns:

Document’s path.

Return type:

Optional[str]

set(value: str) None#

Sets the content of the document.

Parameters:

value (str) – The content of the document.

property source: Any#

Returns the content of the document.

Returns:

The content of the document.

Return type:

Any

unobserve() None#

Unsubscribes to document changes.

This method removes all the callbacks.

property version: str#

Returns the version of the document.

Returns:

Document’s version.

Return type:

str

property ydoc: Doc#

The underlying pycrdt.Doc that contains the data.

Returns:

The document’s ydoc.

Return type:

pycrdt.Doc

property ystate: Map#

A pycrdt.Map containing the state of the document.

Returns:

The document’s state.

Return type:

pycrdt.Map

class jupyter_ydoc.ynotebook.YNotebook(ydoc: Doc | None = None)#

Extends YBaseDoc, and represents a Notebook document.

Schema:

{
    "state": YMap,
    "meta": YMap[
        "nbformat": Int,
        "nbformat_minor": Int,
        "metadata": YMap
    ],
    "cells": YArray[
        YMap[
            "id": str,
            "cell_type": str,
            "source": YText,
            "metadata": YMap,
            "execution_count": Int | None,
            "outputs": [] | None,
            "attachments": {} | None
        ]
    ]
}
append_cell(value: Dict[str, Any]) None#

Appends a cell.

Parameters:

value (Dict[str, Any]) – A cell.

property cell_number: int#

Returns the number of cells in the notebook.

Returns:

The cell number.

Return type:

int

create_ycell(value: Dict[str, Any]) Map#

Creates YMap with the content of the cell.

Parameters:

value (Dict[str, Any]) – A cell.

Returns:

A new cell.

Return type:

pycrdt.Map

property dirty: bool | None#

Returns whether the document is dirty.

Returns:

Whether the document is dirty.

Return type:

Optional[bool]

get() Dict#

Returns the content of the document.

Returns:

Document’s content.

Return type:

Dict

get_cell(index: int) Dict[str, Any]#

Returns a cell.

Parameters:

index (int) – The index of the cell.

Returns:

A cell.

Return type:

Dict[str, Any]

observe(callback: Callable[[str, Any], None]) None#

Subscribes to document changes.

Parameters:

callback (Callable[[str, Any], None]) – Callback that will be called when the document changes.

property path: str | None#

Returns document’s path.

Returns:

Document’s path.

Return type:

Optional[str]

set(value: Dict) None#

Sets the content of the document.

Parameters:

value (Dict) – The content of the document.

set_cell(index: int, value: Dict[str, Any]) None#

Sets a cell into indicated position.

Parameters:
  • index (int) – The index of the cell.

  • value (Dict[str, Any]) – A cell.

set_ycell(index: int, ycell: Map) None#

Sets a Y cell into the indicated position.

Parameters:
  • index (int) – The index of the cell.

  • ycell (pycrdt.Map) – A YMap with the content of a cell.

property source: Any#

Returns the content of the document.

Returns:

The content of the document.

Return type:

Any

unobserve() None#

Unsubscribes to document changes.

This method removes all the callbacks.

property version: str#

Returns the version of the document.

Returns:

Document’s version.

Return type:

str

property ycells#

Returns the Y-cells.

Returns:

The Y-cells.

Return type:

pycrdt.Array

property ydoc: Doc#

The underlying pycrdt.Doc that contains the data.

Returns:

The document’s ydoc.

Return type:

pycrdt.Doc

property ystate: Map#

A pycrdt.Map containing the state of the document.

Returns:

The document’s state.

Return type:

pycrdt.Map

class jupyter_ydoc.yunicode.YUnicode(ydoc: Doc | None = None)#

Extends YBaseDoc, and represents a plain text document, encoded as UTF-8.

Schema:

{
    "state": YMap,
    "source": YText
}
property dirty: bool | None#

Returns whether the document is dirty.

Returns:

Whether the document is dirty.

Return type:

Optional[bool]

get() str#

Returns the content of the document.

Returns:

Document’s content.

Return type:

str

observe(callback: Callable[[str, Any], None]) None#

Subscribes to document changes.

Parameters:

callback (Callable[[str, Any], None]) – Callback that will be called when the document changes.

property path: str | None#

Returns document’s path.

Returns:

Document’s path.

Return type:

Optional[str]

set(value: str) None#

Sets the content of the document.

Parameters:

value (str) – The content of the document.

property source: Any#

Returns the content of the document.

Returns:

The content of the document.

Return type:

Any

unobserve() None#

Unsubscribes to document changes.

This method removes all the callbacks.

property version: str#

Returns the version of the document.

Returns:

Document’s version.

Return type:

str

property ydoc: Doc#

The underlying pycrdt.Doc that contains the data.

Returns:

The document’s ydoc.

Return type:

pycrdt.Doc

property ystate: Map#

A pycrdt.Map containing the state of the document.

Returns:

The document’s state.

Return type:

pycrdt.Map