Skip to main content

Python bindings for prosemirror-rs: a Rust implementation of ProseMirror's document model and transform pipeline

Project description

prosemirror-rs — Python bindings

Python bindings for prosemirror, a Rust implementation of ProseMirror's document model and transform pipeline.

Installation

pip install prosemirror-rs

Design goals

  • Zero unnecessary copies. The schema and document live entirely in Rust memory. Only JSON strings cross the Python/Rust boundary.
  • Wire-efficient. Steps arriving as JSON (e.g. from a WebSocket) can be passed directly to apply_steps_json() without any Python-level parsing.
  • Database-efficient. doc_json() serializes the document in Rust and returns a plain Python str, ready to write to a database with no intermediate Python objects.

Quick start

from prosemirror_rs import Editor
import json

schema_json = json.dumps({
    "nodes": {
        "doc":       {"content": "paragraph+"},
        "paragraph": {"content": "text*", "group": "block"},
        "text":      {"group": "inline"},
    },
    "marks": {"strong": {}, "em": {}},
})

doc_json = json.dumps({
    "type": "doc",
    "content": [{"type": "paragraph", "content": [{"type": "text", "text": "Hello"}]}],
})

editor = Editor(schema_json, doc_json)
print(editor.version)   # 0

# Typical server loop: steps arrive as raw JSON from a client
async def on_message(raw: str):
    data = json.loads(raw)                          # parse envelope only
    results = editor.apply_steps_json(              # steps stay as JSON string
        json.dumps(data["steps"])
    )
    if all(results):
        doc = editor.doc_json()                     # serialised in Rust
        await db.execute("UPDATE docs SET body = $1", doc)

API reference

Editor(schema_json, doc_json)

Create an editor. Both arguments are JSON strings (schema spec and initial document). Raises ValueError on malformed input.

editor.apply_step(step_json) -> bool

Apply one step supplied as a JSON string. Returns True on success, False if the step cannot be applied (document is left unchanged). Raises ValueError on invalid JSON.

editor.apply_steps_json(steps_json, *, stop_on_failure=True) -> list[bool]

Preferred method for incoming network data. Accepts a JSON array of steps as a single string — passed directly to Rust and parsed there, so nothing touches Python's JSON machinery. Returns one bool per step.

editor.apply_steps(steps, *, stop_on_failure=True) -> list[bool]

Convenience method for when steps are constructed or modified in Python. Each element of steps is a JSON string for one step. All steps are parsed before any are applied, so a bad JSON string raises ValueError without mutating the document. Returns one bool per step.

editor.doc_json() -> str

Return the current document as a compact JSON string. Serialized entirely in Rust; only the final string is handed to Python — suitable for direct database writes with no intermediate objects.

editor.version (int, read-only property)

Number of steps successfully applied since construction. Use as a document version counter in collaborative-editing protocols.

Credits

The underlying Rust library was originally written by Daniel Seiler (Xiphoseer, me@dseiler.eu), who designed and implemented the document model, transform pipeline, and runtime schema system. Mustafa J (mustafa.0x@gmail.com) has made substantial contributions to the core Rust implementation. Currently maintained by Johannes Wilm (FidusWriter, johannes@fiduswriter.org).

ProseMirror is by Marijn Haverbeke and contributors — see prosemirror.net.

The Python test suite used for cross-implementation validation is taken from prosemirror-py, a Python port of ProseMirror originally created by Shen Li and maintained by Samuel Cormier-Iijima, Patrick Gingras, and others at Fellow Insights Inc.

License

MIT — see LICENSE.

Copyright 2026 Johannes Wilm Copyright 2025–2026 Mustafa J Copyright 2020 Daniel Seiler Copyright 2019 Fellow Insights Inc. (prosemirror-py Python port) Copyright 2015–2026 Marijn Haverbeke and others

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

prosemirror_rs-0.4.1.tar.gz (141.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

prosemirror_rs-0.4.1-cp314-cp314-win_amd64.whl (753.9 kB view details)

Uploaded CPython 3.14Windows x86-64

prosemirror_rs-0.4.1-cp314-cp314-macosx_11_0_arm64.whl (853.9 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

prosemirror_rs-0.4.1-cp314-cp314-macosx_10_12_x86_64.whl (886.5 kB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

prosemirror_rs-0.4.1-cp310-abi3-manylinux_2_28_x86_64.whl (953.5 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.28+ x86-64

prosemirror_rs-0.4.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (935.2 kB view details)

Uploaded CPython 3.10+manylinux: glibc 2.17+ ARM64

File details

Details for the file prosemirror_rs-0.4.1.tar.gz.

File metadata

  • Download URL: prosemirror_rs-0.4.1.tar.gz
  • Upload date:
  • Size: 141.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for prosemirror_rs-0.4.1.tar.gz
Algorithm Hash digest
SHA256 e69053547f02243760bd1f26a2d0f5b03bc439748f0bf9575acdde0ee65908fd
MD5 5c826a5779f1f17c9e80fff1d31f13f2
BLAKE2b-256 9dbbdc9023d2de991c32c2d4d59722addc6e1b5f1564f09f04cd73751b7d2dbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for prosemirror_rs-0.4.1.tar.gz:

Publisher: publish.yml on fiduswriter/prosemirror-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prosemirror_rs-0.4.1-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for prosemirror_rs-0.4.1-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 4b2689ac93f8203031355c6aae4992fe388cd7956d782571611f456697740f6d
MD5 15fce26e4ce744db912d062b091fd58a
BLAKE2b-256 5ab7b0e3e57ccfbd14eb93db1be34005059b761022e73ebc6b9b3b2228d3e9d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for prosemirror_rs-0.4.1-cp314-cp314-win_amd64.whl:

Publisher: publish.yml on fiduswriter/prosemirror-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prosemirror_rs-0.4.1-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for prosemirror_rs-0.4.1-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 79bc14daa431f62abeaef5749d79bde43d5ddc0fc626131fc065e3f4a682fa1c
MD5 4a050ec2b7c99f4f9daa51c99409481c
BLAKE2b-256 e9a25722b1983e3d04566f11b1b17104dfeed089a4676f29bd67c433deeb799f

See more details on using hashes here.

Provenance

The following attestation bundles were made for prosemirror_rs-0.4.1-cp314-cp314-macosx_11_0_arm64.whl:

Publisher: publish.yml on fiduswriter/prosemirror-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prosemirror_rs-0.4.1-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for prosemirror_rs-0.4.1-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 af4958efd974c9c0fcc69acb5c9b8a6f00735e9e79c76b984978123ae2ac550e
MD5 9674dbab407ebcca7c3a371733d76e3e
BLAKE2b-256 e6d09df7bf06945c9a7c1dd6c619c2c8f662b62870dec807e46d0790a01f43e0

See more details on using hashes here.

Provenance

The following attestation bundles were made for prosemirror_rs-0.4.1-cp314-cp314-macosx_10_12_x86_64.whl:

Publisher: publish.yml on fiduswriter/prosemirror-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prosemirror_rs-0.4.1-cp310-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for prosemirror_rs-0.4.1-cp310-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 7309ac1dbed90f5fa11540615b43f282880997afe33af5bb2df1f9b3e2d7d8ae
MD5 a15319a20c829f10ec193b9a33e21d28
BLAKE2b-256 952de9e07f309bc7868c27ffc145884404c80d1c38e03bd3b54e5cb263b108c8

See more details on using hashes here.

Provenance

The following attestation bundles were made for prosemirror_rs-0.4.1-cp310-abi3-manylinux_2_28_x86_64.whl:

Publisher: publish.yml on fiduswriter/prosemirror-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file prosemirror_rs-0.4.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for prosemirror_rs-0.4.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3a041cfde9becee86999263c42372b19c405c82c037768bf169eaad4c43bf1d9
MD5 21d259b94b7949c2313105ba14af7e40
BLAKE2b-256 34406dc5cd9400ae55d5d7868a5e33b239455e23703f0d8c130161e5251f2510

See more details on using hashes here.

Provenance

The following attestation bundles were made for prosemirror_rs-0.4.1-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: publish.yml on fiduswriter/prosemirror-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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