Skip to main content

CLI that creates a UML class diagram from classes in a Python module or subpackage.

Project description

touml

pronounced /ˈtoo͞m.əl/

A CLI, written in Rust, that converts Python classes to a unified Mermaid diagram.

Installation

pip install touml

# OR (better yet)
uv pip install touml

Usage

# Print help
touml --help

# Print output to stdout
touml path/to/python/files

# Generate an `out.mmd` file in the current directory
touml path/to/python/files -o .

# Print output, but exclude classes, files, and subdirectories matching globs.
touml path/to/python/files --exclude-files "**/__init__.py" "**/config.py" --exclude-dirs "tests" --exclude-classes "Base*"

Tips

# Pipe outputs to `less` to scroll outputs
$ touml path/to/python/files | less

# Pipe outputs to `mmdc` to generate images
$ touml path/to/python/files | mmdc -i -o out.png

# Copy outputs to clipboard
$ touml path/to/python/files | pbcopy

Examples

# Convert all Python files in the test directory to Mermaid diagrams
$ touml tests

classDiagram

    class StrClass {
        + some_other_values tuple[int, ...]
        + value str
        + yet_another_value set[int]
        + get_concatenated(self) str
    }

    Base <|-- StrClass
    StrMixin <|-- StrClass


    class IntClass {
        + value_1 int
        + value_2 list[int]
        + value_3 dict[str, int]
        + check_even(cls, v) int
    }

    Base <|-- IntClass
    IntMixin <|-- IntClass


    class Value {
        + VAL_1
        + VAL_2
        + VAL_3
    }

    `enum.StrEnum` <|-- Value


    class ClassicClass {
        + ANOTHER_CLS_VAR
        + A_CLS_VAR int
        + value
    }


    class Base {
        + id int
        + model_config
    }

    BaseModel <|-- Base


    class BaseMixin {
        + do_something(self)
    }

    `abc.ABC` <|-- BaseMixin


    class IntMixin {
        + do_something(self) int
    }

    BaseMixin <|-- IntMixin
    BaseModel <|-- IntMixin


    class StrMixin {
        + do_something(self) str
    }

    BaseMixin <|-- StrMixin
    BaseModel <|-- StrMixin

Pipe the above to mmdc -i - -t dark -b transparent, and you get: Example

FAQs

What's Mermaid?

Mermaid is a diagramming and charting tool that produces neat diagrams from text. You can learn more about it here.

This tool doesn't generate images!

You're right, young padawan. This tool, intentionally, only generates Mermaid diagram code. To generate images, you can pipe the output to mmdc (the official Mermaid CLI). To download mmdc, take a look at their docs.

Once installed, you can try something like this:

$ touml path/to/python/files | mmdc -i -o out.png

I don't need images, I just want to see the diagrams!

You can copy the output to your clipboard and paste it in a Markdown file, Draw.io, or any other tool that supports Mermaid diagrams.

$ touml path/to/python/files | pbcopy

Why Rust?

The idea was to make touml invocable from a CI pipeline, and we all know how much we want those to be fast.

Sure, but how fast is it?

Blazingly fast, of course. For anecdotal evidence, where I accidentally executed touml against my current directory (including my virtual environment), I was able to generate Mermaid output for 427 Python files in 0.72 seconds. Not convinced? Try it out yourself!

How does it work?

Easy.

  1. Parse all Python files in a given directory, minus those that a user wants to exclude.
  2. Extract all classes and their attributes, using the Python AST.
  3. Generate a Mermaid diagram from the extracted classes and attributes.

Does touml support other languages?

At present, no: touml only generates Mermaid from Python. However, so long as there's a data model that impls the MermaidAdapter trait, sky's the limit.

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

touml-0.1.4.tar.gz (19.2 kB view details)

Uploaded Source

Built Distributions

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

touml-0.1.4-py3-none-win_amd64.whl (1.6 MB view details)

Uploaded Python 3Windows x86-64

touml-0.1.4-py3-none-win32.whl (1.5 MB view details)

Uploaded Python 3Windows x86

touml-0.1.4-py3-none-musllinux_1_2_x86_64.whl (1.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

touml-0.1.4-py3-none-musllinux_1_2_i686.whl (1.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

touml-0.1.4-py3-none-musllinux_1_2_armv7l.whl (1.5 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

touml-0.1.4-py3-none-musllinux_1_2_aarch64.whl (1.5 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

touml-0.1.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.6 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

touml-0.1.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (1.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

touml-0.1.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

touml-0.1.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (1.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

touml-0.1.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

touml-0.1.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.5 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

touml-0.1.4-py3-none-macosx_11_0_arm64.whl (1.5 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

touml-0.1.4-py3-none-macosx_10_12_x86_64.whl (1.6 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

Details for the file touml-0.1.4.tar.gz.

File metadata

  • Download URL: touml-0.1.4.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.3

File hashes

Hashes for touml-0.1.4.tar.gz
Algorithm Hash digest
SHA256 b326d1a7ce2b999ab73d1a1c59257232adfe934e762ffd2d545bbb0b6954ae4a
MD5 79ecf5d78c14a878f86ea056ce4e64e6
BLAKE2b-256 aff824cc4dc51a0b41c7a5fecdca87a4e7e0e304067a4a57b979f047d213fce8

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-win_amd64.whl.

File metadata

  • Download URL: touml-0.1.4-py3-none-win_amd64.whl
  • Upload date:
  • Size: 1.6 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.3

File hashes

Hashes for touml-0.1.4-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 0fb5d94c71be17f05246c6c0c6473c7d07891d45ab9c6ef5b87d40b9150b0861
MD5 3c7f3ab170c9aa3d48e84f8e5e9ed3d2
BLAKE2b-256 3b9c69c911775de04eee9c2f01ccef3e35673efd45a77370e61b1001a9ebde44

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-win32.whl.

File metadata

  • Download URL: touml-0.1.4-py3-none-win32.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: Python 3, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.8.3

File hashes

Hashes for touml-0.1.4-py3-none-win32.whl
Algorithm Hash digest
SHA256 0d9411b9512b42bd6955e531a2cd2ed1fb7542a33be5a9b177830157e350831e
MD5 d9e379e68a365a50d91ef33968ac31d0
BLAKE2b-256 d78787afe7063d3c47be894ba04e3da4cbb44b6b73b9e918d1cd8dc06886bffb

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for touml-0.1.4-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 9cc5c050f2adcd7346ac45c59da0183fc2ae3d5072f946a6a60ba721226c3476
MD5 9e4a808152e1f099b172d08ca9effa17
BLAKE2b-256 0bee3da5f4ddce395846440fce6922e4310fbf5371068d3a094062bcfbb7e894

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-musllinux_1_2_i686.whl.

File metadata

File hashes

Hashes for touml-0.1.4-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 c9a4ba5a31d9187dd5b3e0e8e99d8355033e1790321536108c3b03efdf787565
MD5 3909e22c27aeb517cda4e7f28dc571f9
BLAKE2b-256 1274be06f644ec0cd70ee4cb9d2ef028411cf681cf6f2fc7d96e2bebbe471260

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-musllinux_1_2_armv7l.whl.

File metadata

File hashes

Hashes for touml-0.1.4-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 ee59549862cf7dfd49bf386dd8c27078fa785d978b064166d0be6a3dc6e9d524
MD5 d20a1f810cd0871b59aa716d31cb7ea6
BLAKE2b-256 9d41c8f81363a033499b5c60354523a5d8c6cb88c3f0197706554acb53d5a2ad

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for touml-0.1.4-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 843ba3f209d0f5dea27de11dc00750fe12cd5bd3a56723c2174d10f5c0ebaa26
MD5 2be38aa1a9d4e41e1b9ec8d5b9b2a6a0
BLAKE2b-256 a28bf76a7fc81c3cedf95699dd5600f21703c24773dc6e46ba22cf0f29b3b451

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for touml-0.1.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ac825b30098bcb376a3260ad18a9da9f41851100ddc3243b795017a0ee1f1f2
MD5 bc6ee201efe8e85f401791d73a851626
BLAKE2b-256 614162dd9804b5f1df3b1c212b871e39a04238b9bc28e2c8bc341715bafcd72e

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl.

File metadata

File hashes

Hashes for touml-0.1.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 bb7dbb89fc04ff0ca78dddcc8e97c2c1f8a8b804226f309d77db20b0f6ae6ed7
MD5 5a2692e5da71ef5db73a682c660e0d7a
BLAKE2b-256 0f9bce5617f82b9cc5c00a75a14e2c835b7be2f010a954ab77b032574fcc7438

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl.

File metadata

File hashes

Hashes for touml-0.1.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 16b254239679baa55bd03f27257478d1407275409b4c5ac166c2cd4e9e4bd80b
MD5 bdb96063e2cf9875de686859bffd4fa4
BLAKE2b-256 93a13349488ec751bb99cc37599c7e10867e263404aa4f15cc4da4e6f19a3391

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl.

File metadata

File hashes

Hashes for touml-0.1.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 4b76151e0351b700bb48b5c0797d2780521852e438f5bcd7680eb7d26f796fcc
MD5 82dc3d88fdfc918d6de9a278d1cb046a
BLAKE2b-256 69ee7e02f71eb4d1ca3a9d8250d115f5595e875b35b166360ff11764992050ec

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl.

File metadata

File hashes

Hashes for touml-0.1.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 59412b8d440ec109a1204a2fa7f999c317dbda31855e424d0f7115d158f5387d
MD5 47dff3d1e85f0e64605f0bc2b6561afe
BLAKE2b-256 9f96de8c5afac928bf9d2baba59ace0b2a4d19867c8e4db438fbb3719b95cbeb

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for touml-0.1.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9fd4c3a7d72c590709c4df420b3c9b042dbae5bfac2683b5b49725ec8400195d
MD5 e4940144d85f2e2f405ab602ee8ea3f7
BLAKE2b-256 0aa269e5c8052a8363a166ed4e8daca3de174fdd02a838d1f1939d3eed304489

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for touml-0.1.4-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aa52150b136aa853e9ae2cbba4c6f5ea896c2167e1122f0cb110862e7b553e27
MD5 5c4bb641c7566b1ec5833d66b823d93c
BLAKE2b-256 b4080a86efeb9443eee501e1a65428d9b86562f6ef1bb98387d8d7af40f05fd3

See more details on using hashes here.

File details

Details for the file touml-0.1.4-py3-none-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for touml-0.1.4-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 9503859d675b402d394255b08b5253522e56d983c2ff34f6e03df825a16a177a
MD5 e52d247047dabba7501983f9cb33453f
BLAKE2b-256 725638b2f714215e7a7595e0f63d695cfcb60faa31a86efbc2507e83126c7164

See more details on using hashes here.

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