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. Currently maintained by Johannes Wilm (FidusWriter, johannes@fiduswriter.org).

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

License

MIT — see LICENSE.

Copyright 2026 Johannes Wilm Copyright 2020 Daniel Seiler 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.3.2.tar.gz (73.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.3.2-cp314-cp314-win_amd64.whl (364.5 kB view details)

Uploaded CPython 3.14Windows x86-64

prosemirror_rs-0.3.2-cp314-cp314-macosx_11_0_arm64.whl (465.3 kB view details)

Uploaded CPython 3.14macOS 11.0+ ARM64

prosemirror_rs-0.3.2-cp314-cp314-macosx_10_12_x86_64.whl (481.6 kB view details)

Uploaded CPython 3.14macOS 10.12+ x86-64

prosemirror_rs-0.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (532.5 kB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

prosemirror_rs-0.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (518.9 kB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ ARM64

File details

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

File metadata

  • Download URL: prosemirror_rs-0.3.2.tar.gz
  • Upload date:
  • Size: 73.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.3.2.tar.gz
Algorithm Hash digest
SHA256 779409086d5fe56c1c7cf67e5446567243d89b22334218d2e8445f556c7e625f
MD5 4681c33226b74c71664aa47ec23d9b32
BLAKE2b-256 6fbd8cd1096f469da4c7792d53f1b973d29ef5dd6c7a579a0125f0259205ea6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for prosemirror_rs-0.3.2.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.3.2-cp314-cp314-win_amd64.whl.

File metadata

File hashes

Hashes for prosemirror_rs-0.3.2-cp314-cp314-win_amd64.whl
Algorithm Hash digest
SHA256 28284ac12dcbadcf5e1a15233436da029ec2d97a629a58d266f6da32c53b6a36
MD5 c31422388058d3436ca3cc39625d5817
BLAKE2b-256 3a052ca39a7d84fb1c88930a07c7def7c653b446ae9e54aa337fca586cde07c9

See more details on using hashes here.

Provenance

The following attestation bundles were made for prosemirror_rs-0.3.2-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.3.2-cp314-cp314-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for prosemirror_rs-0.3.2-cp314-cp314-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 c8bac44e864c2da3ae915a1b0434c41c0ab9cc38191a10559f6e98b31e461896
MD5 639b27fb95f4d6b8942caace83eaf3cc
BLAKE2b-256 27bb6d43d6f6993bcaedb74df8f3759f1fabcd806a8de40cc2e5a7ae5eaf75f5

See more details on using hashes here.

Provenance

The following attestation bundles were made for prosemirror_rs-0.3.2-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.3.2-cp314-cp314-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for prosemirror_rs-0.3.2-cp314-cp314-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 42a25340979eab59ac110391791adfef9ccc53e0ce59e991d8518f686a87048d
MD5 1264531aea2516b5ece141f93ed40f8a
BLAKE2b-256 1f050c63f19b5f55fd77edd1808d7e7227e4af1917f87c0a820f70f0b5251c40

See more details on using hashes here.

Provenance

The following attestation bundles were made for prosemirror_rs-0.3.2-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.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for prosemirror_rs-0.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 18ef4af04d9f2786f26ec0fb22bc8b8498187216685789288707dc1448fa050f
MD5 05c9c963d4e46f61cdf785b21e88713b
BLAKE2b-256 c8bfb2722516e377ef07b43390368260e43f041503cff2b0fa6ca20040192c56

See more details on using hashes here.

Provenance

The following attestation bundles were made for prosemirror_rs-0.3.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_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.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for prosemirror_rs-0.3.2-cp38-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cc2bac034065c179378122bf79220f310069fca3746ff03e571221de4be3f22a
MD5 85d64f9e8655e479dcabfe1a87c36c78
BLAKE2b-256 569a667f586703e8f56d22025ccc10ddd47b3d38b5d624cd66fba2897f790cbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for prosemirror_rs-0.3.2-cp38-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