Skip to main content

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

Project description

mermaidmro

Build status Package 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).

class A(object):
    pass

class B(object):
    pass

class C(A):
    pass

class D(A, 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.A --> code.D
    code.B --> code.D
    object --> code.A
    object --> code.B

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

> mermaidmro code:D --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:eNqrVkrOT0lVslJQSi9KLMhQCHGJyVMAApConqOCrq4dhIks7IQhnJ-UlZpcghB2xC7spKSjoJSbWpSbmJkCsrI6RqkkIzU3NQbIiVFKSU1LLM0piVGqVaoFANe4LEk=?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.1.1.tar.gz (9.6 kB view hashes)

Uploaded Source

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