MermaidGenerator
Automatically generate Mermaid class diagrams from Python source code.
MermaidGenerator parses your Python files using the AST and produces a Markdown file with embedded Mermaid class diagrams — no runtime execution required. See an example output.
Made by Fabian Gnatzig in 2026.
Features
- Class attributes with type annotations
- Method signatures including argument types and return types
- Inheritance relationships with links between diagrams
@staticmethodand@classmethod— marked with$@abstractmethod— marked with*@property— rendered as a typed attribute, backing field suppressed- Abstract base classes (
ABC) — rendered with<<abstract>>stereotype @dataclassand other decorators — rendered as Mermaid stereotypes- Public (
+) and private (-) visibility based on naming convention - Union types (
X | Y), generics (list[str]), and qualified types (typing.Optional) - Works on single files or entire project trees
Installation
pip install mermaidgenerator
Usage
python -m mermaidgenerator --src-folder <path> [--doc-path <output>]
| Argument | Required | Description |
|---|---|---|
--src-folder |
yes | Root directory of your Python project to scan |
--doc-path |
no | Output path for the .md file (default: <src-folder>/../class_diagrams.md) |
--exclude |
no | Glob pattern of files to skip, relative to --src-folder (can be repeated) |
Examples
# Basic usage
python -m mermaidgenerator --src-folder src --doc-path docs/class_diagrams.md
# Exclude test files and a specific module
python -m mermaidgenerator --src-folder src --exclude "**/test_*.py" --exclude "migrations/*.py"
Use as a pre-commit hook
Add this to your project's .pre-commit-config.yaml:
- repo: https://github.com/FabianGnatzig/MermaidGenerator
rev: 1.3.0
hooks:
- id: mermaidgenerator
args: [--src-folder, SRC_FOLDER, --doc-path, docs/class_diagrams.md]
args accepts the same flags as the CLI (--src-folder, --doc-path, --exclude). Pin rev to a tag and run pre-commit autoupdate to bump it later.
Example output
Given a class like this:
from abc import ABC, abstractmethod
class Shape(ABC):
"""Abstract base class for shapes."""
def __init__(self, color: str) -> None:
self.color: str = color
@abstractmethod
def area(self) -> float: ...
@staticmethod
def describe(color: str) -> str: ...
MermaidGenerator produces:
# Shape
Abstract base class for shapes.
```mermaid
classDiagram
class Shape {
<<abstract>>
+ str color
- __init__(color: str) None
+ area() float *
+ describe(color: str) str $
}
```
Metadata
Release files for mermaidgenerator 1.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mermaidgenerator-1.3.2.tar.gz | 18.2 kB | With provenance | Details for mermaidgenerator-1.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mermaidgenerator-1.3.2-py3-none-any.whl | Python 3 | none | any | Details for mermaidgenerator-1.3.2-py3-none-any.whl |
Total release size: 37.5 kB
Release files / mermaidgenerator-1.3.2.tar.gz
| Download URL | mermaidgenerator-1.3.2.tar.gz |
|---|---|
| Size | 18.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1df9353588a9b8e46224bfb3bf2c8875feba58bdaf8661a3d67bcb77dd8115cc
|
|
BLAKE2b-256 checksum How to use checksums |
9eb288373785db11f434c90e5c215c05b0f94c746b02061bbd9d082ddc99af62
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.
Transparency logRelease files / mermaidgenerator-1.3.2-py3-none-any.whl
| Download URL | mermaidgenerator-1.3.2-py3-none-any.whl |
|---|---|
| Size | 19.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8de39b6453d819f5b5d936f48cd497380cfee1cd2af471408ffefd2d2de7a437
|
|
BLAKE2b-256 checksum How to use checksums |
95cff9a782e9074ffc94f3fadc17f84036778deae87cc042f85bdef26d9090d9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.
Transparency logSecurity for mermaidgenerator 1.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for mermaidgenerator-1.3.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 26, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.