mermaiden
mermaiden generates deterministic Mermaid source from typed Python diagram models. It supports the Mermaid syntax families registered by the package and validates each diagram before rendering its text.
The package produces Mermaid text only. Render it with Mermaid in a browser, Markdown viewer, or your own CLI workflow.
Installation
Python 3.12 or later is required.
pip install mermaiden
The wheel declares and installs its Python dependencies. The compat CLI command needs no additional tools.
Full SVG validation through Application.validate_render() shells out to the mmdc executable and requires a
compatible browser. Development installs the exact Mermaid CLI version from package-lock.json; set
PUPPETEER_EXECUTABLE_PATH when using a system browser.
Quick start
from mermaiden import Application
with Application.create() as application:
diagrams = application.available_diagrams()
sequence = application.diagram_info("sequenceDiagram")
description = application.diagram_description(sequence.id)
payload_type = application.command_payload(sequence.id, "add_participant")
payload = payload_type.validate({"id": "api", "label": "API", "kind": "control"})
assert sequence in diagrams
assert "add_participant" in description.commands
assert payload.values["kind"] == "control"
Application.available_diagrams() returns the supported diagram catalog. Application.diagram_info(diagram_id) returns the typed diagram API for an individual syntax. CLI workflows are available through python -m mermaiden.cli.
The architecture and ownership map identifies the layers, entry points, lifetimes, and authoritative files behind that catalog.
Application API
Application is the boundary for API and persistence adapters. Each handle uses the process-owned scope created once by
the bootstrap module; use it as a context manager or call close() to invalidate that handle. Create a diagram by
Mermaid syntax id, apply a named domain command, and persist the JSON-safe snapshot returned by the application.
from mermaiden import Application
with Application.create() as application:
diagram = application.create_diagram("sequenceDiagram")
change = application.apply_batch(
diagram,
(
{"operation": "add_participant", "arguments": {"id": "client", "label": "Client"}},
{"operation": "add_participant", "arguments": {"id": "api", "label": "API"}},
{
"operation": "add_message",
"arguments": {
"id": "request",
"source_id": "client",
"target_id": "api",
"label": "Request",
},
},
),
)
assert change.can_commit
payload = application.snapshot(diagram).to_dict()
restored = application.restore(payload)
source = application.render(restored)
report = application.validate_render(restored)
if not report.success:
raise RuntimeError(report.diagnostics)
svg = report.svg
apply_batch() accepts an ordered sequence of {"operation": str, "arguments": mapping} objects. It validates command
payloads as usual, defers whole-diagram constraint inspection until the batch is complete, and restores the exact
pre-batch snapshot if any command or the final validation fails. An empty batch leaves the diagram unchanged and returns
its current validation report.
validate_render() is non-mutating and runs Mermaid's complete rendering and layout phase through mmdc; its report
contains the compatible Mermaid version, SVG output, and structured diagnostics.
Snapshots have a versioned envelope and may be stored as JSON. Version 6 uses registry-owned discriminators such as
mermaiden/element/classDiagram/class; snapshots never contain importable Python module paths. Its closed envelope
schema is published at src/mermaiden/runtime/snapshot/schema.v6.json. Earlier and unknown versions are rejected;
there is no implicit migration or compatibility reader. Newly created and incomplete diagrams are marked as drafts:
callers may snapshot and restore them between accepted commands, but Application.render() rejects them until their
blocking constraints are resolved. Snapshot parsing and typed hydration reject malformed persisted data, and
restoration verifies snapshots that were recorded as valid. Command argument values use the diagram operation names;
JSON string values are accepted for enum arguments.
The caller can discover the REST contract without maintaining a manifest. diagram_description() returns JSON Schema
for the diagram's elements, relations, annotations, and commands. command_payload() returns the generated Pydantic
request model for one command. The generated mutation contract records
the supported update, move, reorder, and retarget behavior for every registered diagram.
Element removal is conservative by default: remove_element rejects an element that still has descendants,
relations, or annotations. Passing cascade: true removes the complete diagram-defined subtree and every dependent
relation and annotation atomically. In Tree View diagrams, branches define that subtree. Removing the final element
returns the diagram to an empty, persistable draft; drafts have no Mermaid source until they become valid again.
Updating and moving elements
Mutation arguments are JSON-shaped and validated before the diagram changes. Updates preserve identity, moves preserve the complete subtree, and reorders require the exact current members of one collection. Rejected mutations leave the complete snapshot unchanged.
from mermaiden import Application
with Application.create() as application:
diagram = application.create_diagram("block")
application.execute(diagram, "add_group", {"id": "source_example", "label": "Source Example"})
application.execute(diagram, "add_group", {"id": "target_example", "label": "Target Example"})
for id, label in (
("first_example", "First Example"),
("second_example", "Second Example"),
("third_example", "Third Example"),
):
application.execute(
diagram,
"add_block",
{"id": id, "label": label, "parent_id": "source_example"},
)
application.execute(
diagram,
"update_element",
{"id": "first_example", "kind": "block_node", "changes": {"label": "Updated First Example"}},
)
application.execute(
diagram,
"move_element",
{"id": "first_example", "kind": "block_node", "parent_id": "target_example", "position": 0},
)
application.execute(
diagram,
"reorder_elements",
{"parent_id": "source_example", "element_ids": ["third_example", "second_example"]},
)
for operation, arguments in (
(
"update_element",
{"id": "first_example", "kind": "block_node", "changes": {"id": "renamed_example"}},
),
(
"move_element",
{"id": "second_example", "kind": "block_node", "parent_id": "third_example"},
),
(
"reorder_elements",
{"parent_id": "source_example", "element_ids": ["second_example"]},
),
):
before = application.snapshot(diagram).to_dict()
try:
application.execute(diagram, operation, arguments)
except RuntimeError:
pass
else:
raise AssertionError(f"{operation} unexpectedly succeeded")
assert application.snapshot(diagram).to_dict() == before
snapshot = application.snapshot(diagram).to_dict()
restored = application.restore(snapshot)
assert application.snapshot(restored).to_dict() == snapshot
assert application.render(restored) == application.render(diagram)
report = application.validate_render(restored)
assert report.success and report.svg
Development
Create the development environment from the committed lock before running repository commands:
uv sync --locked --group dev
The fast tier performs no npm, browser, network, or external Mermaid work:
make fast-check
Full SVG compatibility is an explicit integration tier. It installs the lock-pinned Mermaid CLI once and requires a compatible browser:
make integration
Generate the complete fixture preview without opening a browser; CI runs this non-interactive prerequisite:
make diagrams-preview
The interactive command is local-only and opens the generated preview with the platform open command:
make diagrams-test
The complete host-mode CI target runs quality, pytest, Mermaid compatibility, and package verification concurrently:
make ci
GitHub Actions runs quality, pytest, Mermaid compatibility, and package verification concurrently; the ci job is their
stable aggregate result for branch protection.
License
Mermaiden is proprietary software. No permission to use, copy, modify, or distribute it is granted without prior express written permission. See LICENSE for the complete terms.
Release
Releases are versioned by annotated vX.Y.Z tags. make ci first runs uv lock --check and
uv sync --locked --group dev, so release verification uses the same committed development lock. After it passes,
create and push the tag, then publish the GitHub release:
git tag -a v2.0.0 -m "v2.0.0"
git push origin v2.0.0
gh release create v2.0.0 --verify-tag --generate-notes --title v2.0.0
Metadata
Release files for mermaiden 10.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mermaiden-10.0.0.tar.gz | 176.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mermaiden-10.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 432.1 kB
Release files / mermaiden-10.0.0.tar.gz
| Download URL | mermaiden-10.0.0.tar.gz |
|---|---|
| Size | 176.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
10679a30489a24e9cdfc4a734cbe41ab80b12cb7eeb58f876d92934fc94da0af
|
|
BLAKE2b-256 checksum How to use checksums |
a7c775612ca13530282a7c14767cd4af842a8e3048f074e487911f6959e0d914
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / mermaiden-10.0.0-py3-none-any.whl
| Download URL | mermaiden-10.0.0-py3-none-any.whl |
|---|---|
| Size | 255.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f66b747497bf10f6aa048c57396c4085fadc910ac82548b0a920eec5ffdebba7
|
|
BLAKE2b-256 checksum How to use checksums |
bda3ec2c4198ffb16d787d4a2dbc1563f90294efdafb0a7000340b3a51384d9b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency log