{"library":"mermaid-py","title":"mermaid-py","description":"`mermaid-py` is a Python interface for the popular `mermaid-js` library, simplifying the creation and rendering of diagrams directly from Python code. It currently targets the latest `Mermaid.js v10+` and provides methods to output diagrams as HTML, JSON, or images. The current version is 0.8.4, with releases typically following major Mermaid.js updates or API improvements.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install mermaid-py"],"cli":null},"imports":["from mermaid import Mermaid"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"from mermaid import Mermaid\nimport os\n\n# Define a Mermaid diagram using its text syntax\ngraph_definition = \"\"\"\ngraph TD;\n    A[Start]-->B{Process Data};\n    B-->C[End];\n\"\"\"\n\n# Create a Mermaid object\ndiagram = Mermaid(graph_definition)\n\n# Get the HTML representation to embed or display\nhtml_output = diagram.to_html()\nprint(f\"HTML output starts with: {html_output[:50]}...\")\n\n# Or get the JSON representation\njson_output = diagram.to_json()\nprint(f\"JSON output (first 50 chars): {json_output[:50]}...\")\n\n# To generate an image, you would typically need Playwright installed and configured.\n# Example (requires 'pip install playwright' and 'playwright install chromium'):\n# if os.environ.get('MERMAID_ENABLE_IMAGE_TEST', 'false').lower() == 'true':\n#     try:\n#         image_data = diagram.to_image()\n#         print(f\"Generated image data (bytes length): {len(image_data)}\")\n#     except Exception as e:\n#         print(f\"Could not generate image (requires Playwright setup): {e}\")","lang":"python","description":"This quickstart demonstrates how to define a Mermaid diagram string, create a `Mermaid` object, and retrieve its HTML and JSON representations. Image generation is commented out as it requires additional external dependencies (Playwright) to be installed and configured.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}