y-crdt / ypy

Python bindings to y-crdt

Home Page:https://ypy.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ydoc to json or some readable format

anujism opened this issue · comments

Is it possible with ypy to convert the ydoc contents to some readable format?

Hi @anujism, sorry for the delay. Are you trying to serialize the entire YDoc into something like a json representation?

hi @Waidhoferj no issues. The problem is that I have a ydoc and I am trying to make it searchable. To do that I want to extract the ydoc to some readable format so I can put it into elastic search and make the contents searchable.

We could probably make some iterator method over the root-level types. From there, you can always ask for their content one by one.

Agreed, something like

doc = Y.YDoc(1)
message = doc.get_text("message")
with d.begin_transaction() as txn:
    message.extend("hello!")

# To get the contents of the doc
print(dict(doc.items()))

"""
{
"YText": { "message":  YText("hello!") }
}
"""

yes, an iterator like that would be great!