Skip to main content

mermaid-py-parser

Parse a mermaid text into editable objects.

Repository link: 20001LastOrder/mermaid-parser-py

Motivation

I love Mermaid syntax for it's simplicity and expressiveness in creating diagrams. And I use them in a couple of my projects. However, I found that the lack of a robust Python library for parsing and manipulating Mermaid diagrams was a significant limitation.

This library packages the original JS Mermaid parser and ported it with PythonMonkey so that the parser can be used in Python. As a result, it can parse almost any mermaid code into structured JSON object. I also plan to continue add converting into mermaid-py objects and NertworkX for eaiser editing and analysis.

Installation

Since this project relies on the original MermaidJS package, you need to have Node.js installed in your system.

Then, You can install the library using pip:

pip install mermaid-parser-py

Or install from source:

poetry install

If you want to rebuild the MermaidJS package, you can run the following:

cd mermaid_parser/js
npm install
npx rollup -c

Basic Usage

Converting Any Mermaid Code Into JSON

from mermaid_parser import MermaidParser

parser = MermaidParser()
json_output = parser.parse("graph TD; A-->B; A-->C; B-->D; C-->D;")
print(json_output)

Converting FlowChart to Mermaid-Py

from mermaid_parser import FlowChartConverter

converter = FlowChartConverter()
flowchart = converter.convert("flowchart TD\nA[Start] --> |Process| B[End]")
print(flowchart)

Known Limitation

To get the internal representation of Mermaid Diagrams, it uses the deprecated mermaidAPI object, which may not be available in future versions of Mermaid.

The MermaidJS diagram does not directly work with serverside Node applications. To make it work, I had to hot-patch the MermaidJS pakcage during packaging time to modify the parts using browser features. See mermaid_parser/js/rollup.config.mjs for more details.

Contribution

Any suggestions, issues, or pull requests are more than welcome 🤗!

Run Tests

You can run the tests using pytest:

pytest tests

Metadata

Release files for mermaid-parser-py 0.0.4

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

Source distribution (sdist)

Source distribution for mermaid-parser-py 0.0.4
File Size Uploaded Provenance Actions
mermaid_parser_py-0.0.4.tar.gz 1.3 MB Without provenance Details for mermaid_parser_py-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mermaid-parser-py 0.0.4
File Interpreter ABI Platform Actions
mermaid_parser_py-0.0.4-py3-none-any.whl Python 3 none any Details for mermaid_parser_py-0.0.4-py3-none-any.whl

Total release size: 2.5 MB

Release files / mermaid_parser_py-0.0.4.tar.gz

Download URL mermaid_parser_py-0.0.4.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
1354a6fe182e963d0e8f6e79e58265aaadfdd5ec1594f090edeba81466053212
BLAKE2b-256 checksum
How to use checksums
52562ae3925bc67385daa466cfc20d48b9ba624e3b2f139c34a13d0646f5e1c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.12.11 Darwin/25.1.0

Release files / mermaid_parser_py-0.0.4-py3-none-any.whl

Download URL mermaid_parser_py-0.0.4-py3-none-any.whl
Size 1.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
163f5b748f1d5dde389b4d637535dea87fa15ea6506a830b149382bde380457e
BLAKE2b-256 checksum
How to use checksums
7aa0ab7d6050384d75faf781c28a21aeae0635377d60b070b17a4de710465c17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.4 CPython/3.12.11 Darwin/25.1.0

Security for mermaid-parser-py 0.0.4

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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