Skip to main content

syrenka is mermaid markdown generator

Project description

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

Example

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

SyrenkaFlowchart

Here is the simple flowchart:

SyrenkaFlowchart

and the code behind it:

import syrenka.flowchart as sf
import sys

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

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

fl.to_code(file=sys.stdout)

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:

SyrenkaClassDiagram

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

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

# from io import StringIO
import sys

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())

SyrenkaAstClassDiagram

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

SyrenkaAstClassDiagram

And the code snippet used to generate it:

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

from pathlib import Path

# from io import StringIO
import sys

class_diagram = SyrenkaClassDiagram(
    "syrenka class diagram", SyrenkaClassDiagramConfig().theme(ThemeNames.neutral)
)
class_diagram.add_classes(
    PythonModuleAnalysis.classes_in_path(
        Path(__file__).parent.parent / "src"
    )  # , recursive==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())

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

syrenka-0.4.1.tar.gz (54.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

syrenka-0.4.1-py3-none-any.whl (13.5 kB view details)

Uploaded Python 3

File details

Details for the file syrenka-0.4.1.tar.gz.

File metadata

  • Download URL: syrenka-0.4.1.tar.gz
  • Upload date:
  • Size: 54.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for syrenka-0.4.1.tar.gz
Algorithm Hash digest
SHA256 5a7a7584d516affd853f6734ea40b679f6e184999f274d08303e8de011163227
MD5 19b892a865461d17e552d1061b8b748b
BLAKE2b-256 09edcea9fc25250340d1d38e13c8903470a2c77ffd114e085a38d6dda09f102c

See more details on using hashes here.

Provenance

The following attestation bundles were made for syrenka-0.4.1.tar.gz:

Publisher: python-publish.yml on bartlomiejcieszkowski/syrenka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file syrenka-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: syrenka-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 13.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for syrenka-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3e165491be5aba8da02905a7465ada952b43d726ec737ed42f98623a48996484
MD5 470de0d6f9ab4b8ffc85c2c8a76e9159
BLAKE2b-256 5a1388bc1da184d61678b8a4bc391d10f008b9047607e4cc9b147fc68a3c6214

See more details on using hashes here.

Provenance

The following attestation bundles were made for syrenka-0.4.1-py3-none-any.whl:

Publisher: python-publish.yml on bartlomiejcieszkowski/syrenka

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page