y-py-dart-slate


Namey-py-dart-slate JSON
Version 0.6.3a13 PyPI version JSON
download
home_pageNone
SummaryPython bindings for the Y-CRDT built from yrs (Rust)
upload_time2024-12-18 21:49:50
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseNone
keywords crdt
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [![PyPI version](https://badge.fury.io/py/y-py.svg)](https://badge.fury.io/py/y-py)

# Ypy

Ypy is a Python binding for Y-CRDT. It provides distributed data types that enable real-time collaboration between devices. Ypy can sync data with any other platform that has a Y-CRDT binding, allowing for seamless cross-domain communication. The library is a thin wrapper around Yrs, taking advantage of the safety and performance of Rust.

> [We are looking for a maintainer 👀](https://github.com/y-crdt/ypy/issues/148)

## Installation

```
pip install y-py
```

## Getting Started

Ypy provides many of the same shared data types as [Yjs](https://docs.yjs.dev/). All objects are shared within a `YDoc` and get modified within a transaction block.

```python
import y_py as Y

d1 = Y.YDoc()
# Create a new YText object in the YDoc
text = d1.get_text('test')
# Start a transaction in order to update the text
with d1.begin_transaction() as txn:
    # Add text contents
    text.extend(txn, "hello world!")

# Create another document
d2 = Y.YDoc()
# Share state with the original document
state_vector = Y.encode_state_vector(d2)
diff = Y.encode_state_as_update(d1, state_vector)
Y.apply_update(d2, diff)

value = str(d2.get_text('test'))

assert value == "hello world!"
```

## Development Setup

0. Install [Rust](https://www.rust-lang.org/tools/install) and [Python](https://www.python.org/downloads/)
1. Install `maturin` in order to build Ypy: `pip install maturin`
2. Create a development build of the library: `maturin develop`

## Tests

All tests are located in `/tests`. To run the tests, install `pytest` and run the command line tool from the project root:

```
pip install pytest
pytest
```

## Using Hatch

If you are using `hatch`, there is a `test` environment matrix defined in `pyproject.toml` that will run commands in virtual environments for `py37` through `py312`.

```
hatch run test:maturin develop
hatch run test:pytest
```

## Build Ypy 

Build the library as a wheel and store them in `target/wheels`:

```
maturin build
```

## Ypy in WASM (Pyodide)

As a Rust-based library, Ypy cannot build "pure Python" wheels. CI processes build and upload a number of wheels to PyPI, but PyPI does not support hosting `emscripten` / `wasm32` wheels necessary to import in Pyodide (see https://github.com/pypi/warehouse/issues/10416 for more info and updates). For now, Ypy will build `emscripten` wheels and attach the binaries as assets in the appropriate [Releases](https://github.com/y-crdt/ypy/releases) entry. Unfortunately, trying to install directly from the Github download link will result in a CORS error, so you'll need to use a proxy to pull in the binary and write / install from emscripten file system or host the binary somewhere that is CORS accessible for your application.

You can try out Ypy in Pyodide using the [terminal emulator at pyodide.org](https://pyodide.org/en/stable/console.html):

```
Welcome to the Pyodide terminal emulator 🐍
Python 3.10.2 (main, Sep 15 2022 23:28:12) on WebAssembly/Emscripten
Type "help", "copyright", "credits" or "license" for more information.
>>> wheel_url = 'https://github.com/y-crdt/ypy/releases/download/v0.5.5/y_py-0.5.5-cp310-cp310-emscripten_3_1_14_wasm32.whl'
>>> wheel_name = wheel_url.split('/')[-1]
>>> wheel_name
'y_py-0.5.5-cp310-cp310-emscripten_3_1_14_wasm32.whl'
>>> 
>>> proxy_url = f'https://api.allorigins.win/raw?url={wheel_url}'
>>> proxy_url
'https://api.allorigins.win/raw?url=https://github.com/y-crdt/ypy/releases/download/v0.5.5/y_py-0.5.5-cp310-cp310-emscripten_3_1_14_wasm32.whl'
>>> 
>>> import pyodide
>>> resp = await pyodide.http.pyfetch(proxy_url)
>>> resp.status
200
>>> 
>>> content = await resp.bytes()
>>> len(content)
360133
>>> content[:50]
b'PK\x03\x04\x14\x00\x00\x00\x08\x00\xae\xb2}U\x92l\xa7E\xe6\x04\x00\x00u\t\x00\x00\x1d\x00\x00\x00y_py-0.5.5.dist-info'
>>>
>>> with open(wheel_name, 'wb') as f:
...   f.write(content)
... 
360133
>>> 
>>> import micropip
>>> await micropip.install(f'emfs:./{wheel_name}')
>>> 
>>> import y_py as Y
>>> Y
<module 'y_py' from '/lib/python3.10/site-packages/y_py/__init__.py'>
>>> 
>>> d1 = Y.YDoc()
>>> text = d1.get_text('test')
>>> with d1.begin_transaction() as txn:
    text.extend(txn, "hello world!")
... 
>>> d2 = Y.YDoc()
>>> state_vector = Y.encode_state_vector(d2)
>>> diff = Y.encode_state_as_update(d1, state_vector)
>>> Y.apply_update(d2, diff)
>>> d2.get_text('test')
YText(hello world!)
```


            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "y-py-dart-slate",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "crdt",
    "author": null,
    "author_email": "John Waidhofer <waidhoferj@gmail.com>, Kevin Jahns <kevin.jahns@protonmail.com>, Pierre-Olivier Simonard <pierre.olivier.simonard@gmail.com>",
    "download_url": null,
    "platform": null,
    "description": "[![PyPI version](https://badge.fury.io/py/y-py.svg)](https://badge.fury.io/py/y-py)\n\n# Ypy\n\nYpy is a Python binding for Y-CRDT. It provides distributed data types that enable real-time collaboration between devices. Ypy can sync data with any other platform that has a Y-CRDT binding, allowing for seamless cross-domain communication. The library is a thin wrapper around Yrs, taking advantage of the safety and performance of Rust.\n\n> [We are looking for a maintainer \ud83d\udc40](https://github.com/y-crdt/ypy/issues/148)\n\n## Installation\n\n```\npip install y-py\n```\n\n## Getting Started\n\nYpy provides many of the same shared data types as [Yjs](https://docs.yjs.dev/). All objects are shared within a `YDoc` and get modified within a transaction block.\n\n```python\nimport y_py as Y\n\nd1 = Y.YDoc()\n# Create a new YText object in the YDoc\ntext = d1.get_text('test')\n# Start a transaction in order to update the text\nwith d1.begin_transaction() as txn:\n    # Add text contents\n    text.extend(txn, \"hello world!\")\n\n# Create another document\nd2 = Y.YDoc()\n# Share state with the original document\nstate_vector = Y.encode_state_vector(d2)\ndiff = Y.encode_state_as_update(d1, state_vector)\nY.apply_update(d2, diff)\n\nvalue = str(d2.get_text('test'))\n\nassert value == \"hello world!\"\n```\n\n## Development Setup\n\n0. Install [Rust](https://www.rust-lang.org/tools/install) and [Python](https://www.python.org/downloads/)\n1. Install `maturin` in order to build Ypy: `pip install maturin`\n2. Create a development build of the library: `maturin develop`\n\n## Tests\n\nAll tests are located in `/tests`. To run the tests, install `pytest` and run the command line tool from the project root:\n\n```\npip install pytest\npytest\n```\n\n## Using Hatch\n\nIf you are using `hatch`, there is a `test` environment matrix defined in `pyproject.toml` that will run commands in virtual environments for `py37` through `py312`.\n\n```\nhatch run test:maturin develop\nhatch run test:pytest\n```\n\n## Build Ypy \n\nBuild the library as a wheel and store them in `target/wheels`:\n\n```\nmaturin build\n```\n\n## Ypy in WASM (Pyodide)\n\nAs a Rust-based library, Ypy cannot build \"pure Python\" wheels. CI processes build and upload a number of wheels to PyPI, but PyPI does not support hosting `emscripten` / `wasm32` wheels necessary to import in Pyodide (see https://github.com/pypi/warehouse/issues/10416 for more info and updates). For now, Ypy will build `emscripten` wheels and attach the binaries as assets in the appropriate [Releases](https://github.com/y-crdt/ypy/releases) entry. Unfortunately, trying to install directly from the Github download link will result in a CORS error, so you'll need to use a proxy to pull in the binary and write / install from emscripten file system or host the binary somewhere that is CORS accessible for your application.\n\nYou can try out Ypy in Pyodide using the [terminal emulator at pyodide.org](https://pyodide.org/en/stable/console.html):\n\n```\nWelcome to the Pyodide terminal emulator \ud83d\udc0d\nPython 3.10.2 (main, Sep 15 2022 23:28:12) on WebAssembly/Emscripten\nType \"help\", \"copyright\", \"credits\" or \"license\" for more information.\n>>> wheel_url = 'https://github.com/y-crdt/ypy/releases/download/v0.5.5/y_py-0.5.5-cp310-cp310-emscripten_3_1_14_wasm32.whl'\n>>> wheel_name = wheel_url.split('/')[-1]\n>>> wheel_name\n'y_py-0.5.5-cp310-cp310-emscripten_3_1_14_wasm32.whl'\n>>> \n>>> proxy_url = f'https://api.allorigins.win/raw?url={wheel_url}'\n>>> proxy_url\n'https://api.allorigins.win/raw?url=https://github.com/y-crdt/ypy/releases/download/v0.5.5/y_py-0.5.5-cp310-cp310-emscripten_3_1_14_wasm32.whl'\n>>> \n>>> import pyodide\n>>> resp = await pyodide.http.pyfetch(proxy_url)\n>>> resp.status\n200\n>>> \n>>> content = await resp.bytes()\n>>> len(content)\n360133\n>>> content[:50]\nb'PK\\x03\\x04\\x14\\x00\\x00\\x00\\x08\\x00\\xae\\xb2}U\\x92l\\xa7E\\xe6\\x04\\x00\\x00u\\t\\x00\\x00\\x1d\\x00\\x00\\x00y_py-0.5.5.dist-info'\n>>>\n>>> with open(wheel_name, 'wb') as f:\n...   f.write(content)\n... \n360133\n>>> \n>>> import micropip\n>>> await micropip.install(f'emfs:./{wheel_name}')\n>>> \n>>> import y_py as Y\n>>> Y\n<module 'y_py' from '/lib/python3.10/site-packages/y_py/__init__.py'>\n>>> \n>>> d1 = Y.YDoc()\n>>> text = d1.get_text('test')\n>>> with d1.begin_transaction() as txn:\n    text.extend(txn, \"hello world!\")\n... \n>>> d2 = Y.YDoc()\n>>> state_vector = Y.encode_state_vector(d2)\n>>> diff = Y.encode_state_as_update(d1, state_vector)\n>>> Y.apply_update(d2, diff)\n>>> d2.get_text('test')\nYText(hello world!)\n```\n\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Python bindings for the Y-CRDT built from yrs (Rust)",
    "version": "0.6.3a13",
    "project_urls": {
        "Homepage": "https://github.com/its-dart/ypy",
        "Issues": "https://github.com/its-dart/ypy/issues",
        "Pypi": "https://pypi.org/project/y-py-dart",
        "Source": "https://github.com/its-dart/ypy"
    },
    "split_keywords": [
        "crdt"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b1062c17b9da40a82780ded594f2d67ac5a7a38e15c98bf1345a5e630793c5a5",
                "md5": "aacf6e0b223392fdc80fd2a2309c876c",
                "sha256": "96dae99df9a351c84bd6f48cc0cf1dfd12f11f40358e52d578d8dcfad9f5fc01"
            },
            "downloads": -1,
            "filename": "y_py_dart_slate-0.6.3a13-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl",
            "has_sig": false,
            "md5_digest": "aacf6e0b223392fdc80fd2a2309c876c",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": null,
            "size": 1578947,
            "upload_time": "2024-12-18T21:49:50",
            "upload_time_iso_8601": "2024-12-18T21:49:50.410865Z",
            "url": "https://files.pythonhosted.org/packages/b1/06/2c17b9da40a82780ded594f2d67ac5a7a38e15c98bf1345a5e630793c5a5/y_py_dart_slate-0.6.3a13-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "58d9ce3fa87e2583c587ac2ac42423e5b681b4f70122d5c1213a1d66fb5b20a2",
                "md5": "51c92087bd9f3eff2c6cd4e71362ba62",
                "sha256": "a07df04142969ee645766f7dfc97cc0e2a083f78fc8b27a4edaf0d4d0b926e7f"
            },
            "downloads": -1,
            "filename": "y_py_dart_slate-0.6.3a13-cp311-cp311-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "51c92087bd9f3eff2c6cd4e71362ba62",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": null,
            "size": 1679048,
            "upload_time": "2024-12-18T21:41:45",
            "upload_time_iso_8601": "2024-12-18T21:41:45.324326Z",
            "url": "https://files.pythonhosted.org/packages/58/d9/ce3fa87e2583c587ac2ac42423e5b681b4f70122d5c1213a1d66fb5b20a2/y_py_dart_slate-0.6.3a13-cp311-cp311-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-18 21:49:50",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "its-dart",
    "github_project": "ypy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "y-py-dart-slate"
}
        
Elapsed time: 0.45927s