syrenka


Namesyrenka JSON
Version 0.5.6 PyPI version JSON
download
home_pageNone
Summaryeasily create mermaid diagrams with python, generate class diagrams from python ast, more languages support coming
upload_time2025-07-09 09:21:16
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9.16
licenseMIT License Copyright (c) 2025 Bartlomiej Cieszkowski Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords markdown mermaid mermaid.js
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # syrenka
syrenka is mermaid markdown generator

## Description

The aim of this project is to provide easy to use classes for generating mermaid charts and diagrams.

## Installation

`pip install syrenka`

## CLI

To use syrenka from command line try:

```
python -m syrenka -h
```

for example, to generate python classdiagram:
```
python -m syrenka classdiagram <path/to/folder>
```

to generate python class diagram for project with src/ structure we can either do:
```
python -m syrenka classdiagram <project_dir>/src
```
or
```
python -m syrenka classdiagram <project_dir> --detect-project-dir
```

- there is also option to filter files, see `python -m syrenka classdiagram -h` for more details
- there is now an option to put global functions/assignments in pseudo-class _globals_ per module with flag `--globals-as-class`


## Example

Diagrams displayed here are generated from mermaid markdown generated by syrenka converted with `mmdc` into svg.

### SyrenkaAstClassDiagram
This is example is using python `ast` approach for generating the class diagram.

<!-- EX3_MERMAID_DIAGRAM_BEGIN -->
![SyrenkaAstClassDiagram](https://raw.githubusercontent.com/bartlomiejcieszkowski/syrenka/refs/heads/main/syrenka_diagram-3.svg "SyrenkaAstClassDiagram")
<!-- EX3_MERMAID_DIAGRAM_END -->

And the code snippet used to generate it:

<!-- EX3_SYRENKA_CODE_BEGIN -->
```python
"""Example SyrenkaClassDiagram with ast backend."""

# from io import StringIO
import sys
from pathlib import Path

from syrenka.base import ThemeNames
from syrenka.classdiagram import SyrenkaClassDiagram, SyrenkaClassDiagramConfig
from syrenka.lang.python import PythonModuleAnalysis

class_diagram = SyrenkaClassDiagram("syrenka class diagram", SyrenkaClassDiagramConfig().theme(ThemeNames.NEUTRAL))
class_diagram.add_classes(PythonModuleAnalysis.classes_in_path(Path(__file__).parent.parent / "src"))

# file can be anything that implements TextIOBase
# out = StringIO() # string buffer in memory
out = sys.stdout  # stdout
# out = open("syrenka.md", "w") # write it to file

class_diagram.to_code(file=out)

# StringIO
# out.seek(0)
# print(out.read())
```
<!-- EX3_SYRENKA_CODE_END -->

### SyrenkaClassDiagram
This example uses `importlib.import_module` + `ast` approach.
Here are current classes in syrenka module - syrenka generated mermaid diagram, rendered to svg with use of mmdc:

<!-- EX1_MERMAID_DIAGRAM_BEGIN -->
![SyrenkaClassDiagram](https://raw.githubusercontent.com/bartlomiejcieszkowski/syrenka/refs/heads/main/syrenka_diagram-1.svg "SyrenkaClassDiagram")
<!-- EX1_MERMAID_DIAGRAM_END -->

So how do we get it?
This is a code snippet that does it:

<!-- EX1_SYRENKA_CODE_BEGIN -->
```python
"""Example SyrenkaClassDiagram."""

# from io import StringIO
import sys

from syrenka.base import ThemeNames
from syrenka.classdiagram import SyrenkaClassDiagram, SyrenkaClassDiagramConfig
from syrenka.lang.python import PythonModuleAnalysis

class_diagram = SyrenkaClassDiagram("syrenka class diagram", SyrenkaClassDiagramConfig().theme(ThemeNames.NEUTRAL))
class_diagram.add_classes(PythonModuleAnalysis.classes_in_module(module_name="syrenka", nested=True))

# file can be anything that implements TextIOBase
# out = StringIO() # string buffer in memory
out = sys.stdout  # stdout
# out = open("syrenka.md", "w") # write it to file

class_diagram.to_code(file=out)

# StringIO
# out.seek(0)
# print(out.read())
```
<!-- EX1_SYRENKA_CODE_END -->

### SyrenkaFlowchart

#### Sample flowchart
Here is the sample flowchart:

<!-- EX4_MERMAID_DIAGRAM_BEGIN -->
![SyrenkaFlowchart_SampleFlowchart](https://raw.githubusercontent.com/bartlomiejcieszkowski/syrenka/refs/heads/main/syrenka_diagram-4.svg "SyrenkaFlowchart_SampleFlowchart")
<!-- EX4_MERMAID_DIAGRAM_END -->

and the code behind it:

<!-- EX4_SYRENKA_CODE_BEGIN -->
```python
"""Example SyrenkaFlowchart usage."""

from io import StringIO
from pathlib import Path

import syrenka.flowchart as sf
from syrenka.generate import generate_diagram_image

flowchart = sf.SyrenkaFlowchart(
    "",
    sf.FlowchartDirection.TOP_TO_BOTTOM,
    nodes=[
        sf.Subgraph(
            "one",
            nodes=[
                sf.Node("a1"),
                sf.Node("a2"),
            ],
        ),
        sf.Subgraph(
            "two",
            direction=sf.FlowchartDirection.LEFT_TO_RIGHT,
            nodes=[
                sf.Node("b1"),
                sf.Node("b2"),
            ],
        ),
        sf.Subgraph(
            "three",
            direction=sf.FlowchartDirection.BOTTOM_TO_TOP,
            nodes=[
                sf.Node("c1"),
                sf.Node("c2"),
            ],
        ),
    ],
)

flowchart.connect_by_id("c1", "a2").connect_by_id("a1", "a2")
flowchart.connect_by_id("b1", "b2").connect_by_id("c1", "c2")
flowchart.connect_by_id("one", "two").connect_by_id("three", "two").connect_by_id("two", "c2")

out = StringIO()
flowchart.to_code(file=out)

print(out.getvalue())

generate_diagram_image(out.getvalue(), Path("out.svg"), overwrite=True)
```
<!-- EX4_SYRENKA_CODE_END -->

#### Simple flowchart
Here is the simple flowchart:

<!-- EX2_MERMAID_DIAGRAM_BEGIN -->
```mermaid
---
title: Simple Flowchart
---
flowchart TB
    1 --> 2
    2 -.-> 3
    3 --> 4
    4 ==> s
    1["First"]
    subgraph s["Subgraph"]
        2["Second"]
        3["Third"]
    end
    4["Fourth"]
```
<!-- EX2_MERMAID_DIAGRAM_END -->

and the code behind it:

<!-- EX2_SYRENKA_CODE_BEGIN -->
```python
"""Example Simple SyrenkaFlowchart."""

import sys

import syrenka.flowchart as sf

fl = sf.SyrenkaFlowchart(title="Simple Flowchart", direction=sf.FlowchartDirection.TOP_TO_BOTTOM)
fl.add(sf.Node(identifier="1", text="First"))
sub = sf.Subgraph(identifier="s", text="Subgraph")
sub.add(sf.Node(identifier="2", text="Second"))
sub.add(sf.Node(identifier="3", text="Third"))
fl.add(sub)
fl.add(sf.Node(identifier="4", text="Fourth"))

fl.connect_by_id("1", "2")
fl.connect_by_id(source_id="2", target_id="3", edge_type=sf.EdgeType.DOTTED_LINK)
fl.connect_by_id("3", "4").connect_by_id("4", "s", sf.EdgeType.THICK_LINK)

fl.to_code(file=sys.stdout)
```
<!-- EX2_SYRENKA_CODE_END -->

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "syrenka",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9.16",
    "maintainer_email": null,
    "keywords": "markdown, mermaid, mermaid.js",
    "author": null,
    "author_email": "Bartlomiej Cieszkowski <bartlomiej.cieszkowski@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a1/15/8fb12a6fd576c03701dee4181f4916cd99a3e4f251cd124b6a83c3d92367/syrenka-0.5.6.tar.gz",
    "platform": null,
    "description": "# syrenka\nsyrenka is mermaid markdown generator\n\n## Description\n\nThe aim of this project is to provide easy to use classes for generating mermaid charts and diagrams.\n\n## Installation\n\n`pip install syrenka`\n\n## CLI\n\nTo use syrenka from command line try:\n\n```\npython -m syrenka -h\n```\n\nfor example, to generate python classdiagram:\n```\npython -m syrenka classdiagram <path/to/folder>\n```\n\nto generate python class diagram for project with src/ structure we can either do:\n```\npython -m syrenka classdiagram <project_dir>/src\n```\nor\n```\npython -m syrenka classdiagram <project_dir> --detect-project-dir\n```\n\n- there is also option to filter files, see `python -m syrenka classdiagram -h` for more details\n- there is now an option to put global functions/assignments in pseudo-class _globals_ per module with flag `--globals-as-class`\n\n\n## Example\n\nDiagrams displayed here are generated from mermaid markdown generated by syrenka converted with `mmdc` into svg.\n\n### SyrenkaAstClassDiagram\nThis is example is using python `ast` approach for generating the class diagram.\n\n<!-- EX3_MERMAID_DIAGRAM_BEGIN -->\n![SyrenkaAstClassDiagram](https://raw.githubusercontent.com/bartlomiejcieszkowski/syrenka/refs/heads/main/syrenka_diagram-3.svg \"SyrenkaAstClassDiagram\")\n<!-- EX3_MERMAID_DIAGRAM_END -->\n\nAnd the code snippet used to generate it:\n\n<!-- EX3_SYRENKA_CODE_BEGIN -->\n```python\n\"\"\"Example SyrenkaClassDiagram with ast backend.\"\"\"\n\n# from io import StringIO\nimport sys\nfrom pathlib import Path\n\nfrom syrenka.base import ThemeNames\nfrom syrenka.classdiagram import SyrenkaClassDiagram, SyrenkaClassDiagramConfig\nfrom syrenka.lang.python import PythonModuleAnalysis\n\nclass_diagram = SyrenkaClassDiagram(\"syrenka class diagram\", SyrenkaClassDiagramConfig().theme(ThemeNames.NEUTRAL))\nclass_diagram.add_classes(PythonModuleAnalysis.classes_in_path(Path(__file__).parent.parent / \"src\"))\n\n# file can be anything that implements TextIOBase\n# out = StringIO() # string buffer in memory\nout = sys.stdout  # stdout\n# out = open(\"syrenka.md\", \"w\") # write it to file\n\nclass_diagram.to_code(file=out)\n\n# StringIO\n# out.seek(0)\n# print(out.read())\n```\n<!-- EX3_SYRENKA_CODE_END -->\n\n### SyrenkaClassDiagram\nThis example uses `importlib.import_module` + `ast` approach.\nHere are current classes in syrenka module - syrenka generated mermaid diagram, rendered to svg with use of mmdc:\n\n<!-- EX1_MERMAID_DIAGRAM_BEGIN -->\n![SyrenkaClassDiagram](https://raw.githubusercontent.com/bartlomiejcieszkowski/syrenka/refs/heads/main/syrenka_diagram-1.svg \"SyrenkaClassDiagram\")\n<!-- EX1_MERMAID_DIAGRAM_END -->\n\nSo how do we get it?\nThis is a code snippet that does it:\n\n<!-- EX1_SYRENKA_CODE_BEGIN -->\n```python\n\"\"\"Example SyrenkaClassDiagram.\"\"\"\n\n# from io import StringIO\nimport sys\n\nfrom syrenka.base import ThemeNames\nfrom syrenka.classdiagram import SyrenkaClassDiagram, SyrenkaClassDiagramConfig\nfrom syrenka.lang.python import PythonModuleAnalysis\n\nclass_diagram = SyrenkaClassDiagram(\"syrenka class diagram\", SyrenkaClassDiagramConfig().theme(ThemeNames.NEUTRAL))\nclass_diagram.add_classes(PythonModuleAnalysis.classes_in_module(module_name=\"syrenka\", nested=True))\n\n# file can be anything that implements TextIOBase\n# out = StringIO() # string buffer in memory\nout = sys.stdout  # stdout\n# out = open(\"syrenka.md\", \"w\") # write it to file\n\nclass_diagram.to_code(file=out)\n\n# StringIO\n# out.seek(0)\n# print(out.read())\n```\n<!-- EX1_SYRENKA_CODE_END -->\n\n### SyrenkaFlowchart\n\n#### Sample flowchart\nHere is the sample flowchart:\n\n<!-- EX4_MERMAID_DIAGRAM_BEGIN -->\n![SyrenkaFlowchart_SampleFlowchart](https://raw.githubusercontent.com/bartlomiejcieszkowski/syrenka/refs/heads/main/syrenka_diagram-4.svg \"SyrenkaFlowchart_SampleFlowchart\")\n<!-- EX4_MERMAID_DIAGRAM_END -->\n\nand the code behind it:\n\n<!-- EX4_SYRENKA_CODE_BEGIN -->\n```python\n\"\"\"Example SyrenkaFlowchart usage.\"\"\"\n\nfrom io import StringIO\nfrom pathlib import Path\n\nimport syrenka.flowchart as sf\nfrom syrenka.generate import generate_diagram_image\n\nflowchart = sf.SyrenkaFlowchart(\n    \"\",\n    sf.FlowchartDirection.TOP_TO_BOTTOM,\n    nodes=[\n        sf.Subgraph(\n            \"one\",\n            nodes=[\n                sf.Node(\"a1\"),\n                sf.Node(\"a2\"),\n            ],\n        ),\n        sf.Subgraph(\n            \"two\",\n            direction=sf.FlowchartDirection.LEFT_TO_RIGHT,\n            nodes=[\n                sf.Node(\"b1\"),\n                sf.Node(\"b2\"),\n            ],\n        ),\n        sf.Subgraph(\n            \"three\",\n            direction=sf.FlowchartDirection.BOTTOM_TO_TOP,\n            nodes=[\n                sf.Node(\"c1\"),\n                sf.Node(\"c2\"),\n            ],\n        ),\n    ],\n)\n\nflowchart.connect_by_id(\"c1\", \"a2\").connect_by_id(\"a1\", \"a2\")\nflowchart.connect_by_id(\"b1\", \"b2\").connect_by_id(\"c1\", \"c2\")\nflowchart.connect_by_id(\"one\", \"two\").connect_by_id(\"three\", \"two\").connect_by_id(\"two\", \"c2\")\n\nout = StringIO()\nflowchart.to_code(file=out)\n\nprint(out.getvalue())\n\ngenerate_diagram_image(out.getvalue(), Path(\"out.svg\"), overwrite=True)\n```\n<!-- EX4_SYRENKA_CODE_END -->\n\n#### Simple flowchart\nHere is the simple flowchart:\n\n<!-- EX2_MERMAID_DIAGRAM_BEGIN -->\n```mermaid\n---\ntitle: Simple Flowchart\n---\nflowchart TB\n    1 --> 2\n    2 -.-> 3\n    3 --> 4\n    4 ==> s\n    1[\"First\"]\n    subgraph s[\"Subgraph\"]\n        2[\"Second\"]\n        3[\"Third\"]\n    end\n    4[\"Fourth\"]\n```\n<!-- EX2_MERMAID_DIAGRAM_END -->\n\nand the code behind it:\n\n<!-- EX2_SYRENKA_CODE_BEGIN -->\n```python\n\"\"\"Example Simple SyrenkaFlowchart.\"\"\"\n\nimport sys\n\nimport syrenka.flowchart as sf\n\nfl = sf.SyrenkaFlowchart(title=\"Simple Flowchart\", direction=sf.FlowchartDirection.TOP_TO_BOTTOM)\nfl.add(sf.Node(identifier=\"1\", text=\"First\"))\nsub = sf.Subgraph(identifier=\"s\", text=\"Subgraph\")\nsub.add(sf.Node(identifier=\"2\", text=\"Second\"))\nsub.add(sf.Node(identifier=\"3\", text=\"Third\"))\nfl.add(sub)\nfl.add(sf.Node(identifier=\"4\", text=\"Fourth\"))\n\nfl.connect_by_id(\"1\", \"2\")\nfl.connect_by_id(source_id=\"2\", target_id=\"3\", edge_type=sf.EdgeType.DOTTED_LINK)\nfl.connect_by_id(\"3\", \"4\").connect_by_id(\"4\", \"s\", sf.EdgeType.THICK_LINK)\n\nfl.to_code(file=sys.stdout)\n```\n<!-- EX2_SYRENKA_CODE_END -->\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2025 Bartlomiej Cieszkowski\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.",
    "summary": "easily create mermaid diagrams with python, generate class diagrams from python ast, more languages support coming",
    "version": "0.5.6",
    "project_urls": {
        "Bug Tracker": "https://github.com/bartlomiejcieszkowski/syrenka/issues",
        "Homepage": "https://github.com/bartlomiejcieszkowski/syrenka"
    },
    "split_keywords": [
        "markdown",
        " mermaid",
        " mermaid.js"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1f19218505d7d8cb405a781292b944859cdd0fa26390a87e6787e26198319609",
                "md5": "9f7f5ca2b32b33f0e2593566fa97dfe5",
                "sha256": "6dd55a4d9a24f8b5663e0aa9d255bb3a045b10d94dfa050fb5348f5ceb38cd49"
            },
            "downloads": -1,
            "filename": "syrenka-0.5.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9f7f5ca2b32b33f0e2593566fa97dfe5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9.16",
            "size": 18576,
            "upload_time": "2025-07-09T09:21:14",
            "upload_time_iso_8601": "2025-07-09T09:21:14.737678Z",
            "url": "https://files.pythonhosted.org/packages/1f/19/218505d7d8cb405a781292b944859cdd0fa26390a87e6787e26198319609/syrenka-0.5.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "a1158fb12a6fd576c03701dee4181f4916cd99a3e4f251cd124b6a83c3d92367",
                "md5": "35568046c15d2063d4e865b58b0053a1",
                "sha256": "28f9b07326728efb67837cf868caa61c122a9e9f1806b5f979b204be2705d050"
            },
            "downloads": -1,
            "filename": "syrenka-0.5.6.tar.gz",
            "has_sig": false,
            "md5_digest": "35568046c15d2063d4e865b58b0053a1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9.16",
            "size": 186985,
            "upload_time": "2025-07-09T09:21:16",
            "upload_time_iso_8601": "2025-07-09T09:21:16.251667Z",
            "url": "https://files.pythonhosted.org/packages/a1/15/8fb12a6fd576c03701dee4181f4916cd99a3e4f251cd124b6a83c3d92367/syrenka-0.5.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-09 09:21:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "bartlomiejcieszkowski",
    "github_project": "syrenka",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "syrenka"
}
        
Elapsed time: 0.49769s