easily create mermaid diagrams with python, generate class diagrams from python ast, more languages support coming
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
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 -hfor 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.
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())
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:
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())
SyrenkaFlowchart
Here is the simple flowchart:
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)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file syrenka-0.4.12.tar.gz.
File metadata
- Download URL: syrenka-0.4.12.tar.gz
- Upload date:
- Size: 77.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6e94158b1da3b1c6b2ca0d811dc53a3a6fb0a3621160400c9aff1bb5ab76930
|
|
| MD5 |
9d5bf2985ae07ba42386c1154ea13611
|
|
| BLAKE2b-256 |
2e2890628edd7a8b399b3d378d89014b6154533d87dc46562e6eb8c3c53f827b
|
Provenance
The following attestation bundles were made for syrenka-0.4.12.tar.gz:
Publisher:
python-publish.yml on bartlomiejcieszkowski/syrenka
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
syrenka-0.4.12.tar.gz -
Subject digest:
d6e94158b1da3b1c6b2ca0d811dc53a3a6fb0a3621160400c9aff1bb5ab76930 - Sigstore transparency entry: 204052482
- Sigstore integration time:
-
Permalink:
bartlomiejcieszkowski/syrenka@b160221c705915479ce025ef2b32a5ba041d2d7b -
Branch / Tag:
refs/tags/v0.4.12 - Owner: https://github.com/bartlomiejcieszkowski
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b160221c705915479ce025ef2b32a5ba041d2d7b -
Trigger Event:
release
-
Statement type:
File details
Details for the file syrenka-0.4.12-py3-none-any.whl.
File metadata
- Download URL: syrenka-0.4.12-py3-none-any.whl
- Upload date:
- Size: 15.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72bbcda4482f9b8685e7e592e268263bffa2cb6725bf964150e18b659aaacf4b
|
|
| MD5 |
9652484a14b88b221dcd5c7223c051c3
|
|
| BLAKE2b-256 |
b59f872ba4353bff1cf58994b77f25231d76b7d1bc2f8ce9f7267f12631024b7
|
Provenance
The following attestation bundles were made for syrenka-0.4.12-py3-none-any.whl:
Publisher:
python-publish.yml on bartlomiejcieszkowski/syrenka
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
syrenka-0.4.12-py3-none-any.whl -
Subject digest:
72bbcda4482f9b8685e7e592e268263bffa2cb6725bf964150e18b659aaacf4b - Sigstore transparency entry: 204052484
- Sigstore integration time:
-
Permalink:
bartlomiejcieszkowski/syrenka@b160221c705915479ce025ef2b32a5ba041d2d7b -
Branch / Tag:
refs/tags/v0.4.12 - Owner: https://github.com/bartlomiejcieszkowski
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@b160221c705915479ce025ef2b32a5ba041d2d7b -
Trigger Event:
release
-
Statement type: