Skip to main content

Generator to create mermaid class diagrams.

Project description

MermaidGenerator

Automatically generate Mermaid class diagrams from Python source code.

PyPI version Python License

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
  • @staticmethod and @classmethod — marked with $
  • @abstractmethod — marked with *
  • @property — rendered as a typed attribute, backing field suppressed
  • Abstract base classes (ABC) — rendered with <<abstract>> stereotype
  • @dataclass and 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 $
}
```

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

mermaidgenerator-1.3.1.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

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

mermaidgenerator-1.3.1-py3-none-any.whl (19.3 kB view details)

Uploaded Python 3

File details

Details for the file mermaidgenerator-1.3.1.tar.gz.

File metadata

  • Download URL: mermaidgenerator-1.3.1.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for mermaidgenerator-1.3.1.tar.gz
Algorithm Hash digest
SHA256 3d419e24c4a09580068ee7c7c9c5bd8f37d9e7dc0c0c9ba5f54fdfb99d19277f
MD5 f3430aa38d029a1020252ab62888c2f5
BLAKE2b-256 54c08a04a97f99b36bd2a93fe941cd199ac06853d7440e5f23ee4d21c11a25d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for mermaidgenerator-1.3.1.tar.gz:

Publisher: publish.yaml on FabianGnatzig/MermaidGenerator

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

File details

Details for the file mermaidgenerator-1.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mermaidgenerator-1.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dcc1a782e9b10fa577a2c06dbb7dca035b3bdd7aea53cc4baceec5f75a7f4a2d
MD5 6659c1b562d8ab723067fdb704b7b7e6
BLAKE2b-256 a4fb5c662ce7e810273d1a9d6bcde5023f948f13b7dcd8801deea1fa48d910b3

See more details on using hashes here.

Provenance

The following attestation bundles were made for mermaidgenerator-1.3.1-py3-none-any.whl:

Publisher: publish.yaml on FabianGnatzig/MermaidGenerator

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