Skip to main content

Python bindings for Yrs

Project description

Build Status Code style: black

pycrdt

CRDTs based on Yrs.

Install

pip install pycrdt

Usage

pycrdt offers the following shared data types:

  • Text: a type similar to a str.
  • Array: a type similar to a list.
  • Map: a type similar to a dict.

You can initialize them with their Python built-in counterparts:

from pycrdt import Text, Array, Map

text0 = Text("Hello")
array0 = Array([0, "foo"])
map0 = Map({"key0": "value0"})

But they are pretty useless on their own. They are just placeholders waiting to be inserted in a shared document. Only then do they really become useful:

from pycrdt import Doc

doc = Doc()
doc["text0"] = text0
doc["array0"] = array0
doc["map0"] = map0

Now you can operate on them as you would expect, for instance:

text0 += ", World!"
array0.append("bar")
map0["key1"] = "value1"

Note that an Array and a Map can hold other shared data types:

map1 = Map({"foo": 1})
array1 = Array([5, 6, 7])

array0.append(map1)
map0["key2"] = array1

Every change to doc (a modified/added/deleted value) will generate an update in the form of some encoded binary data. You can listen to these updates and send them on the wire, so that they can be applied to a remote document.

We say that text0, array0 and map0 are root types of doc. When they got inserted into doc, we gave them a name. For instance, text0 was inserted under "text0". This is how a remote document will retrieve the root types of the document, after applying the received updates:

from pycrdt import Doc, Text, Array, Map

remote_doc = Doc()
remote_doc.apply_updates(updates)

text0 = Text()
array0 = Array()
map0 = Map()
remote_doc["text0"] = text0
remote_doc["array0"] = array0
remote_doc["map0"] = map0

You could say that there is nothing fancy here, it's just about encoding data changes so that they can be applied on another object. But this is where the magic of CRDTs comes into play. Their algorithm ensures that if some changes are done concurrently on different objects representing the same data (for instance on different machines), applying the changes will lead to the same data on all objects. Without such algorithms, this property doesn't hold due to the fact that changes depend on the order in which they are applied, and that they take time to travel on the wire.

The most common example is inserting a different character on a text editor on two machines. Say we start with a blank page on both editors, and the user on machine A inserts "a" at the same time the user on machine B inserts "b". After receiving the other user's update, if no special care is taken, machine A will show "ba" and machine B will show "ab". In other words, their document states will diverge, and thus users won't collaborate on the same document anymore. CRDTs ensure that documents don't diverge, their shared documents will eventually have the same state. It will arbitrary be "ab" or "ba", but it will be the same on both machines.

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

pycrdt-0.3.2.tar.gz (20.7 kB view hashes)

Uploaded Source

Built Distributions

pycrdt-0.3.2-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pycrdt-0.3.2-pp39-pypy39_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

pycrdt-0.3.2-pp39-pypy39_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

pycrdt-0.3.2-pp39-pypy39_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

pycrdt-0.3.2-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pycrdt-0.3.2-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

pycrdt-0.3.2-pp39-pypy39_pp73-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.3 MB view hashes)

Uploaded PyPy macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pycrdt-0.3.2-pp39-pypy39_pp73-macosx_10_7_x86_64.whl (654.9 kB view hashes)

Uploaded PyPy macOS 10.7+ x86-64

pycrdt-0.3.2-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

pycrdt-0.3.2-pp38-pypy38_pp73-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ s390x

pycrdt-0.3.2-pp38-pypy38_pp73-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ppc64le

pycrdt-0.3.2-pp38-pypy38_pp73-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARMv7l

pycrdt-0.3.2-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

pycrdt-0.3.2-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded PyPy manylinux: glibc 2.5+ i686

pycrdt-0.3.2-pp38-pypy38_pp73-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.3 MB view hashes)

Uploaded PyPy macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pycrdt-0.3.2-pp38-pypy38_pp73-macosx_10_7_x86_64.whl (654.9 kB view hashes)

Uploaded PyPy macOS 10.7+ x86-64

pycrdt-0.3.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ x86-64

pycrdt-0.3.2-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.8 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ s390x

pycrdt-0.3.2-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ppc64le

pycrdt-0.3.2-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARMv7l

pycrdt-0.3.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.17+ ARM64

pycrdt-0.3.2-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.5+ i686

pycrdt-0.3.2-cp312-cp312-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.3 MB view hashes)

Uploaded CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pycrdt-0.3.2-cp312-cp312-macosx_10_7_x86_64.whl (653.5 kB view hashes)

Uploaded CPython 3.12 macOS 10.7+ x86-64

pycrdt-0.3.2-cp311-none-win_amd64.whl (462.3 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

pycrdt-0.3.2-cp311-none-win32.whl (438.1 kB view hashes)

Uploaded CPython 3.11 Windows x86

pycrdt-0.3.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ x86-64

pycrdt-0.3.2-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ s390x

pycrdt-0.3.2-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ppc64le

pycrdt-0.3.2-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARMv7l

pycrdt-0.3.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.17+ ARM64

pycrdt-0.3.2-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.5+ i686

pycrdt-0.3.2-cp311-cp311-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.3 MB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pycrdt-0.3.2-cp311-cp311-macosx_10_7_x86_64.whl (654.9 kB view hashes)

Uploaded CPython 3.11 macOS 10.7+ x86-64

pycrdt-0.3.2-cp310-none-win_amd64.whl (462.6 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

pycrdt-0.3.2-cp310-none-win32.whl (438.1 kB view hashes)

Uploaded CPython 3.10 Windows x86

pycrdt-0.3.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

pycrdt-0.3.2-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ s390x

pycrdt-0.3.2-cp310-cp310-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ppc64le

pycrdt-0.3.2-cp310-cp310-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARMv7l

pycrdt-0.3.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.17+ ARM64

pycrdt-0.3.2-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.5+ i686

pycrdt-0.3.2-cp310-cp310-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.3 MB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pycrdt-0.3.2-cp310-cp310-macosx_10_7_x86_64.whl (654.9 kB view hashes)

Uploaded CPython 3.10 macOS 10.7+ x86-64

pycrdt-0.3.2-cp39-none-win_amd64.whl (463.2 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

pycrdt-0.3.2-cp39-none-win32.whl (438.5 kB view hashes)

Uploaded CPython 3.9 Windows x86

pycrdt-0.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

pycrdt-0.3.2-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ s390x

pycrdt-0.3.2-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ppc64le

pycrdt-0.3.2-cp39-cp39-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARMv7l

pycrdt-0.3.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.17+ ARM64

pycrdt-0.3.2-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.5+ i686

pycrdt-0.3.2-cp39-cp39-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.3 MB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pycrdt-0.3.2-cp39-cp39-macosx_10_7_x86_64.whl (654.7 kB view hashes)

Uploaded CPython 3.9 macOS 10.7+ x86-64

pycrdt-0.3.2-cp38-none-win_amd64.whl (462.1 kB view hashes)

Uploaded CPython 3.8 Windows x86-64

pycrdt-0.3.2-cp38-none-win32.whl (438.3 kB view hashes)

Uploaded CPython 3.8 Windows x86

pycrdt-0.3.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

pycrdt-0.3.2-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ s390x

pycrdt-0.3.2-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ppc64le

pycrdt-0.3.2-cp38-cp38-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARMv7l

pycrdt-0.3.2-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.17+ ARM64

pycrdt-0.3.2-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.8 manylinux: glibc 2.5+ i686

pycrdt-0.3.2-cp38-cp38-macosx_10_9_x86_64.macosx_11_0_arm64.macosx_10_9_universal2.whl (1.3 MB view hashes)

Uploaded CPython 3.8 macOS 10.9+ universal2 (ARM64, x86-64) macOS 10.9+ x86-64 macOS 11.0+ ARM64

pycrdt-0.3.2-cp38-cp38-macosx_10_7_x86_64.whl (655.6 kB view hashes)

Uploaded CPython 3.8 macOS 10.7+ x86-64

pycrdt-0.3.2-cp37-none-win_amd64.whl (462.3 kB view hashes)

Uploaded CPython 3.7 Windows x86-64

pycrdt-0.3.2-cp37-none-win32.whl (438.2 kB view hashes)

Uploaded CPython 3.7 Windows x86

pycrdt-0.3.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

pycrdt-0.3.2-cp37-cp37m-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ s390x

pycrdt-0.3.2-cp37-cp37m-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.7 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ppc64le

pycrdt-0.3.2-cp37-cp37m-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARMv7l

pycrdt-0.3.2-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.17+ ARM64

pycrdt-0.3.2-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.whl (1.6 MB view hashes)

Uploaded CPython 3.7m manylinux: glibc 2.5+ i686

pycrdt-0.3.2-cp37-cp37m-macosx_10_7_x86_64.whl (655.7 kB view hashes)

Uploaded CPython 3.7m macOS 10.7+ x86-64

Supported by

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