Skip to main content

Create mermaid graphs from the method resolution order (mro) of Python objects.

Project description

mermaidmro

Build status Package version Python version Documentation status Code coverge License

Create mermaid graphs from the method resolution order (mro) of Python objects.

CLI Examples

For the examples below, let's consider the following classes saved in a file code.py that can be imported via import code (adjust your PYTHONPATH if this is not the case).

# code.py

class A(object):
    pass

class B(object):
    pass

class C(A):
    pass

class D(C, B):
    pass

Generate mermaid text

Simply pass the module and class in the format module_name:class_name to mermaidmro.

> mermaidmro code:D

graph TD
    code.D("code.D (0)")
    code.C("code.C (1)")
    code.A("code.A (2)")
    code.B("code.B (3)")
    object("object (4)")

    code.C --> code.D
    code.B --> code.D
    code.A --> code.C
    object --> code.B
    object --> code.A

You can hide the mro indices by adding --no-mro / -n.

> mermaidmro code:D --no-mro

graph TD
    code.C --> code.D
    code.B --> code.D
    code.A --> code.C
    object --> code.B
    object --> code.A

You can also limit the maximum depth via --max-depth / -m.

> mermaidmro code:D --no-mro --max-depth 1

graph TD
    code.A --> code.D
    code.B --> code.D

Open the graph in your browser

Just configure the executable of your browser you like to open the graph with via --cmd / -c (on Macs this is usually just open). This functionality is based on the mermaid.live service.

> mermaidmro code:D --cmd open

# opens https://mermaid.ink/img/pako:eNptkM8KwjAMh18l5JSBE_-dPAht9wgec6lbdYrdZNTT2LvbUUvLWE6_fB8kISPWfWPwDPgY9KeFa8Ud-JrptiLGEIB2BWORORWdAtovnIhOAB0WTkYngY7J9beXqZ13IQCdgss3Qlle_oflA9exSFjlKxKW61jgBtCawepnM_9lZHStsYZ9w9iYu_6-HeOE0w_Nr1i5?type=png

To open the graph in the live editor, add --edit.

Visualize the graph in your terminal

This requires that you have a tool installed that lets you visualize images in your terminal, e.g. imgcat for iTerm2.

> mermaidmro code:D --visualize imgcat

# shows

code:D graph

Download the graph

> mermaidmro code:D --download graph.png

Installation

Simply install via pip

pip install mermaidmro

Development

If you like to contribute, I'm happy to receive pull requests. Just make sure to add a new test cases and run linting and coverage checks:

> ./tests/test.sh
> ./tests/lint.sh
> ./tests/coverage.sh

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

mermaidmro-0.2.1.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

mermaidmro-0.2.1-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file mermaidmro-0.2.1.tar.gz.

File metadata

  • Download URL: mermaidmro-0.2.1.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for mermaidmro-0.2.1.tar.gz
Algorithm Hash digest
SHA256 e471b0103aaf36182a86ba2a2d5ec68c8b28488a981624d863a2bb0a8abac41b
MD5 117f3524c1c6b0c4c41a2ffc483d7d35
BLAKE2b-256 b1c6a1e118d23e5b6957a30e21a09e41405ada155320250e20f2b59b0b10e036

See more details on using hashes here.

File details

Details for the file mermaidmro-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: mermaidmro-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for mermaidmro-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9c71fd110f4bc7333ee24fc718102928aa92ae0f62cfde6cd6f3c86de1bdf877
MD5 f7f5a20ddab6420c693424dd12535597
BLAKE2b-256 38c16d72c65ab56e020f20ec6ad8152b6db0ae1650b829f5d9da6ba639b299ea

See more details on using hashes here.

Supported by

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