🎉 Big News for Python Developers & Mermaid Fans: 'mmdc' Makes Mermaid Diagrams Easy as Python! 🚀
Source: Dev.to
What Is Mermaid?
Mermaid is an open‑source diagramming tool that lets you define diagrams using simple, text‑based syntax — very similar to Markdown — and render them into real diagrams.
You write plain text like:
graph TD
A --> B
B --> C
…and Mermaid turns it into a visual flowchart you can embed in docs, wikis, blogs, or technical writing. It’s fast to learn, version‑control friendly, and integrates with many tools. (Mermaid)
Why mmdc Is a Game Changer
Traditionally, converting Mermaid into SVG, PNG, or PDF required:
- Node.js
- npm
- Mermaid CLI
- Browsers or headless workers
- Extra system tools
mmdc changes all that. It’s a pure Python solution — installable with a single pip install, and it works without installing ANY external tools. It uses the powerhouse library Phasma, which leverages an internal PhantomJS instance to render Mermaid code into real diagram outputs — yet you never have to install anything else yourself. This makes it perfect for Python environments, automation, docs pipelines, and CI/CD workflows.
Installation
pip install mmdc
That’s all — you’re ready to go! No Node.js, npm, apt installs, or browsers required.
Use It from the Command Line
Convert a simple Mermaid file to SVG:
mmdc --input my_diagram.mmd --output my_diagram.svg
Create PNG or PDF just by specifying the extension:
mmdc --input my_diagram.mmd --output my_diagram.png
mmdc --input my_diagram.mmd --output my_diagram.pdf
Perfect for automated doc builds, static site generators, or blog pipelines!
Use It in Python Too
Generate diagrams directly from your Python code:
from mmdc import MermaidConverter
converter = MermaidConverter()
mermaid_text = """
graph TD
A[Start] --> B{Is it cool?}
B -->|Yes| C[Love it!]
B ---->|No| D[Try again]
"""
converter.to_svg(mermaid_text, output_file="cool_diagram.svg")
Simple, powerful, and integrates cleanly with Python applications, docs generators, notebook workflows, and automation scripts!
Example Mermaid Code Snippets
Flowchart
graph LR
A[Idea] --> B[Develop]
B --> C[Test]
C --> D[Deploy]
Simple Loop
flowchart TD
Start --> Process
Process --> Review
Review -->|OK| End
Review -->|Fix| Process
Sequence Diagram
sequenceDiagram
Alice->>Bob: Hello Bob!
Bob-->>Alice: Hi Alice!
Why This Matters
- No external setup: Python developers finally get Mermaid without any extra installs.
- Fits docs automation: Great for Sphinx, MkDocs, Jupyter, notebooks, and CI/CD.
- Python‑centric workflows: Treat diagrams as first‑class parts of your codebase.
Wrap Up
If you’ve ever wanted a clean, Python‑only way to generate Mermaid diagrams, mmdc is huge news. It brings a beloved text‑based diagramming approach straight into the Python ecosystem — all with a single pip install.
Now diagrams can truly be code first — versioned, automated, lightweight, and beautiful — without the weight of external toolchains. 💥