Skip to main content

Mermaiden

Let the machine draw. Keep the meaning.

Software can generate a diagram in an instant. The harder problem is knowing whether that diagram still means what you intended after an agent, tool, or application changes it.

Mermaiden turns diagrams into typed, discoverable state. It validates semantic commands, can apply related changes atomically, preserves versioned snapshots, and renders deterministic Mermaid source—so automation can move quickly without turning meaning into guesswork.

The package produces Mermaid text rather than owning its presentation. Render that text in a Markdown viewer, a browser, or your own Mermaid CLI workflow.

Documentation

Installation

Python 3.12 or later is required.

pip install mermaiden

Source generation needs no browser or Mermaid executable. Application.validate_render() additionally requires the compatible mmdc executable and a browser.

Discover a diagram contract

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_contract = application.command_payload(sequence.id, "add_participant")
    payload = payload_contract.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 runtime catalog. diagram_description() and command_payload() expose the same strict contracts used by command execution, so an adapter does not need a parallel operation manifest.

Create, persist, and render

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)

Snapshots use a closed, versioned envelope with registry-owned identities rather than Python import paths. Drafts may be persisted and restored, but rendering requires every blocking constraint to be resolved. See Persist and restore diagrams for the exact boundary. Use application.upgrade_snapshot(payload) to upgrade historical v6–v11 snapshots explicitly to v12, with structured change and loss reports. restore() stays strict; documented information loss requires allow_loss=True.

To validate the generated source as SVG, first follow the consumer setup in Render and validate Mermaid.

Update, move, and reorder

from mermaiden import Application

with Application.create() as application:
    diagram = application.create_diagram("block")
    application.execute(diagram, "add_group", {"id": "source", "label": "Source"})
    application.execute(diagram, "add_group", {"id": "target", "label": "Target"})
    application.execute(
        diagram,
        "add_block",
        {"id": "catalog", "label": "Catalog", "parent_id": "source"},
    )
    application.execute(
        diagram,
        "update_element",
        {"id": "catalog", "kind": "block_node", "changes": {"label": "Product Catalog"}},
    )
    application.execute(
        diagram,
        "move_element",
        {"id": "catalog", "kind": "block_node", "parent_id": "target", "position": 0},
    )
    snapshot = application.snapshot(diagram).to_dict()
    restored = application.restore(snapshot)
    assert application.render(restored) == application.render(diagram)

The generated mutation contract records update, move, reorder, and retarget semantics and per-diagram coverage. Use Mutate diagrams for task-focused mutation, removal, and atomic-rejection guidance.

Development

Create the development environment and run the fast tier:

uv sync --locked --group dev
make fast-check

The contribution guide covers repository verification and generated contracts. Documentation is built strictly with make documentation-check; external links are checked with make documentation-linkcheck.

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.

Metadata

Release files for mermaiden 15.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mermaiden 15.1.0
File Size Uploaded Provenance Actions
mermaiden-15.1.0.tar.gz 3.5 MB With provenance Details for mermaiden-15.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mermaiden 15.1.0
File Interpreter ABI Platform Actions
mermaiden-15.1.0-py3-none-any.whl Python 3 none any Details for mermaiden-15.1.0-py3-none-any.whl

Total release size: 3.8 MB

Release files / mermaiden-15.1.0.tar.gz

Download URL mermaiden-15.1.0.tar.gz
Size 3.5 MB
Tags Source
SHA-256 checksum
How to use checksums
1887e9a8a63e681a6e5440ae0e3d10eefa2236f2541f83f1bcf917adf3d3cf37
BLAKE2b-256 checksum
How to use checksums
376b2c7d4bab40356057a1b8d5bd9b528cd3f28fdccc59398a47b44fa976764f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 6, 2026.

Transparency log

Release files / mermaiden-15.1.0-py3-none-any.whl

Download URL mermaiden-15.1.0-py3-none-any.whl
Size 298.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
235694b1a94c9327fc6e6836327be72b2df60b8e51114fe80efaa23ee8b4efad
BLAKE2b-256 checksum
How to use checksums
f2054baafa1660e4e038756ec3e50e8f6e18fe4fc0a0b138096057f33b7cf430
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 6, 2026.

Transparency log

Security for mermaiden 15.1.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for mermaiden-15.1.0.tar.gz

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 Nov 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page