mermaid-python is a Python package (version 0.1) for generating diagrams using Mermaid JS. It allows you to define Mermaid diagrams as strings and render them into standalone HTML files. The project has not seen updates since its initial release over three years ago (March 2021), meaning it may not support newer Mermaid JS features or address recent issues. It is effectively abandoned.
pip install mermaid-pythonVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a Mermaid graph using a string and render it into a standalone HTML file. The `Mermaid` class takes the diagram definition, and `to_file()` saves it. You then open the HTML file in a browser to see the rendered diagram.
Be aware that it may not support recent Mermaid JS features, syntax changes, or security fixes from newer Mermaid JS versions. Consider alternative, more actively maintained libraries, or directly using Mermaid JS with a dedicated CLI or web service.
For direct SVG or PNG image output, you will need to open the generated HTML file in a headless browser (e.g., using Playwright, Selenium, or Puppeteer via a subprocess) and take a screenshot, or integrate with an external Mermaid CLI tool (like `mermaid-cli` or `@mermaid-js/mermaid-cli`).
Validate your Mermaid diagram string using the official Mermaid Live Editor (https://mermaid.live/) before passing it to the `Mermaid()` constructor. Check the browser's developer console when opening the HTML file for Mermaid JS specific errors.
Ensure you have installed the library correctly: `pip install mermaid-python`. If using virtual environments, activate the correct environment before running your script.
Verify your Mermaid diagram string for any syntax errors using the Mermaid Live Editor (https://mermaid.live/). Also, open the generated HTML file in a browser and check its developer console for JavaScript errors related to Mermaid.
Ensure that the directory where you intend to save the HTML file exists. You can create it programmatically using `os.makedirs(os.path.dirname(output_filename), exist_ok=True)` before calling `to_file()`.