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.2.tar.gz (18.8 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.2-py3-none-win_amd64.whl (1.6 MB view details)

Uploaded Python 3Windows x86-64

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

Uploaded Python 3Windows x86

touml-0.1.2-py3-none-musllinux_1_2_x86_64.whl (1.8 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

touml-0.1.2-py3-none-musllinux_1_2_i686.whl (1.8 MB view details)

Uploaded Python 3musllinux: musl 1.2+ i686

touml-0.1.2-py3-none-musllinux_1_2_armv7l.whl (1.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARMv7l

touml-0.1.2-py3-none-musllinux_1_2_aarch64.whl (1.7 MB view details)

Uploaded Python 3musllinux: musl 1.2+ ARM64

touml-0.1.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64

touml-0.1.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.0 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ s390x

touml-0.1.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (1.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ppc64le

touml-0.1.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl (1.9 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ i686

touml-0.1.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARMv7l

touml-0.1.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64

touml-0.1.2-py3-none-macosx_11_0_arm64.whl (1.6 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

touml-0.1.2-py3-none-macosx_10_12_x86_64.whl (1.7 MB view details)

Uploaded Python 3macOS 10.12+ x86-64

File details

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

File metadata

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

File hashes

Hashes for touml-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1991d78995787b7e4146bcb99b41e916a1e27e6453f716aa1ea30681607bcb63
MD5 2d39f708ff138ad90b1f094ad0a0c4bd
BLAKE2b-256 a8583edd2e44032778b17de3a7a7c97ba9bd5425dfd61f94ffc67114f66cc3c6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: touml-0.1.2-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.7.8

File hashes

Hashes for touml-0.1.2-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 813a65f92de1bf0658f251ec75301fa8bbe242da577294fcb6b7f5b82c9661bf
MD5 716e18e984992892469ddc66d4566f5b
BLAKE2b-256 1cb5d4593f566c572af3041a4ee5e345decea528179299422d559c2e15fef597

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for touml-0.1.2-py3-none-win32.whl
Algorithm Hash digest
SHA256 affb93e02ea13a30dae0fee9803f2536dfb8123357481e057ba3dffad508f2b9
MD5 16c26ff515b3637c6d329531bd299b0d
BLAKE2b-256 212be62207467a0aa4dccd97d43243ddf1625e34a50f539c852d886b2bef1258

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for touml-0.1.2-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 6023c1942d8cf77d91c00ed5511a36d0b525bfbf36d28b74a4de3b1a99e275f8
MD5 cbf3a55b7007e01a489ef2785e2a6895
BLAKE2b-256 8b264f0732619fc710eea76f7483c2e32ce780d72a313b484bab9c0d8969fed7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for touml-0.1.2-py3-none-musllinux_1_2_i686.whl
Algorithm Hash digest
SHA256 8164f18351bf69ee425c02866c6393987b7543b964fe7131e8b61ac94efcbd11
MD5 e8c2da4cbf96f0bff18ee7802fde310d
BLAKE2b-256 5ffe4bad6d0d83099d5962ca87083f13f777457868ff25da0c3786932e640f12

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for touml-0.1.2-py3-none-musllinux_1_2_armv7l.whl
Algorithm Hash digest
SHA256 32f8e3beed95b1ce18808bc6b6e456f8b479ebc70deb3fb3effca816d41dd253
MD5 044f7752ec071c64f2e62aff79d0a9a6
BLAKE2b-256 a0ae043ea75a7f1b885bdcb10ee52b60acd0e46f991ea6b87416b6a6c9055877

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for touml-0.1.2-py3-none-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 538835920fc1b0f82743177c16488a947be8c4c53360950e6aa85caae5e32487
MD5 5312ba6a4156f4122be82a35ee8e46ac
BLAKE2b-256 944af6d45dde029f714b727e1eff1c0dc2e2aaf645c6406b42aebe5efceffbf7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for touml-0.1.2-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 839d8d4f711270a8bb1a1648f15b01f246fc782cce70575b013fc7a7fa6ee7bb
MD5 6b7a5df741319ef3137c4ef2cda0473c
BLAKE2b-256 1de45d698a65c99e70b03807f6192b419c7ac1a880d9767bc0a4a3ccc5c7cfa7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for touml-0.1.2-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
Algorithm Hash digest
SHA256 b3c2bc26c2a3a6c5b2923d5174f4e07f417f62a8c8ead603bc895f1d38cb6293
MD5 02616c37298a85aebec4ffbe8ee8ebd1
BLAKE2b-256 625843d35622c4b654a244d8f72688d92d438bd148c5deb70d4d04b0a1dd431c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for touml-0.1.2-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
Algorithm Hash digest
SHA256 362d9937d9a3da7bfc826dd0990c592980536abb45781622ab1ec503ec0ad8ee
MD5 730c530393e9219f1a3a754356500240
BLAKE2b-256 4a37eb0601b8117bb745b02912f4353ba976e9fe004331d7ad7c559a4bb592f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for touml-0.1.2-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm Hash digest
SHA256 3a4077267eecfe84c2d9511c92ee90f45ec1dc436c0e7c4435c4910265680888
MD5 e034328729272866371d36ba08d1b2fc
BLAKE2b-256 f6c9a29dc37a666458a72bcca51d36d6abc524e6854d6ee4b66021e6745d204c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for touml-0.1.2-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
Algorithm Hash digest
SHA256 f005a1acb07719c1738cbad015c0a2089d09828ab14cf01c5fcb3fc5bc7846ad
MD5 62ddfbce882aaf0d524c6778137aab85
BLAKE2b-256 01aa2c68ef1adbb08f1e57208c00914d6e36c53160e6011b7a018ee7ac3ce864

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for touml-0.1.2-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4711da24ee9db860b01989ce75b13d0050cdfed5bf1ea2d6df560060fc039c3a
MD5 0addc601d912a9f5a30992f38181560f
BLAKE2b-256 4ccb1dc643ce20c328b31c814042e83d4b46084bcb86e9d46feba1f62d9dd61b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for touml-0.1.2-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f2415f0e5304e55115934a09db4817a139b1d3bca55d209a44aaa08c0b77fd98
MD5 102ad4a1f3ad7bdcc136eb211db2e462
BLAKE2b-256 6f3b8785d0b4c894b5ca06bf9847ef26a42c541c9a363aa28e1beb243aeb30b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for touml-0.1.2-py3-none-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 d6add56f2bad7316d1bcfce62f7f8ad62e693fd6dbf5671b0345b459fd8cfa15
MD5 aa1e03c9ac73b6692db1116f43fe4c61
BLAKE2b-256 f3dfae4143f3af71bb7aed75fc42fdab20179ec9783ddd19b6b7b04c658e31c1

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