Skip to main content

Python MermaidJS Markup Builder

MermaidJS Markup builder helps to script MermaidJS markup creation.

MermaidJS is an amazing product, but the syntax is very human readable and writeable (comparing to graphviz for exmaple).

for example, node or arrow shape on a flowchart is something that is easy to see as ASCII, but not easy to adhoc script.

This library should help to write mermaidJS markup, which then can be rendered in Markdown/github or playground.

NOTE: This is Work in progress

Next tasks on my list:

  • styling for flowchart (adding classes and styles)
  • "clone with prefix" (creates a clone of a node or a subgraph but adds a prefix to ID, so the don't conflict)
  • class diagrams
  • groups for sequence diagrams
  • package for distribution

Examples:

Flow chart

untyped version

chart = (Chart(title='test1')
    .add_node('user')
    .add_node('client')
    .add_node('server')
    .add_node('database')
    .add_link_between('user', 'client')
    .add_link_between('client', 'server')
    .add_link_between('server', 'database'))

OOP (more complicated version)

chart = Chart(title='Test', direction=ChartDir.TB)
node1 = Node(title="this is my node", id='my-node', shape=NodeShape.HEXAGON)
node2 = Node(title="this is my second node")
chart.add_node(node1).add_node(node2)
link = Link(src=node1.get_id(), dest=node2.get_id(), text='this is my link')
chart.add_link(link)
subgraph = Subgraph(title='subgraph', direction=ChartDir.LR)
subgraph.add_node(Node(title='i am a node inside subgraph'))

subgraph2 = Subgraph(title='subgraph2', direction=ChartDir.LR)
sn1 = Node(title='subnode 2')
sn2 = Node(title='subnode 3')
(subgraph2
    .add_node(sn1)
    .add_node(sn2)
    .add_link(Link(src=sn1, dest=sn2, text='link between subnodes')))
subgraph.add_subgraph(subgraph2)
chart.add_subgraph(subgraph)

Sequence diagram

diagram = SequenceDiagram()
client = Participant(id='C', label='Client')
server = Participant(id='S', label='Server')
database = Participant(id='D', label='Database')
(diagram
    .add_participant(client)
    .add_participant(server)
    .add_participant(database)
    .add_message(Message(src=client, dest=server, text='HTTP Request', activation_mode=ActivationMode.ACTIVATE))
    .add_message(Message(src=server, dest=database, text='SQL Query'))
    .add_message(Message(src=database, dest=server, text='Result', arrow=ArrowType.DOTTED_LINE_NO_ARROW))        
    .add_message(Message(src=server, dest=client, text='HTTP Response', activation_mode=ActivationMode.DEACTIVATE))
    .add_note(Note(participants=[client], text='This is a note', position=NotePosition.LEFT_OF)))

see flowchart_test.py and sequence_diagram_test.py for more examples.

Development

This library doesn't have any dependencies.

python3 -m venv venv
source venv/bin/activate
pip3 install -e .

Just use python3.5+ , as it's using types and Union

Run tests

pytest

to preview - paste results to https://www.devtoolsdaily.com/diagrams/mermaidjs/playground/

Metadata

Release files for mermaid-builder 0.0.3

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-builder 0.0.3
File Size Uploaded
mermaid_builder-0.0.3.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mermaid-builder 0.0.3
File Interpreter ABI Platform
mermaid_builder-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 13.9 kB

Release files / mermaid_builder-0.0.3.tar.gz

Download URL mermaid_builder-0.0.3.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3016ef25668bcb28de4a4746aabdfaa531c06a7e7f89fa1596e6a274c7c73705
BLAKE2b-256 checksum
How to use checksums
6457d83e7e62de05adbba2476b7596ed4a253907a4f4c19be74c40e7ce2944dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.10.9

Release files / mermaid_builder-0.0.3-py3-none-any.whl

Download URL mermaid_builder-0.0.3-py3-none-any.whl
Size 6.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
decd7d25268bda7a520ce0cab7873e50fac1e33b41e5a1dd7daec5c0ae3c7ffb
BLAKE2b-256 checksum
How to use checksums
5f4e7480454b7ee7de5c2c8561e83b4564196ecf1c9847e893dfbb51032e5a3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.10.9

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

0.0.1

2 release files

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