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:
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.
- Parse all Python files in a given directory, minus those that a user wants to exclude.
- Extract all classes and their attributes, using the Python AST.
- 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.
Metadata
Release files for touml 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| touml-0.1.4.tar.gz | 19.2 kB | Details |
Built distributions (wheels)
Total release size: 22.7 MB
Release files / touml-0.1.4.tar.gz
| Download URL | touml-0.1.4.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b326d1a7ce2b999ab73d1a1c59257232adfe934e762ffd2d545bbb0b6954ae4a
|
|
BLAKE2b-256 checksum How to use checksums |
aff824cc4dc51a0b41c7a5fecdca87a4e7e0e304067a4a57b979f047d213fce8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-win_amd64.whl
| Download URL | touml-0.1.4-py3-none-win_amd64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
0fb5d94c71be17f05246c6c0c6473c7d07891d45ab9c6ef5b87d40b9150b0861
|
|
BLAKE2b-256 checksum How to use checksums |
3b9c69c911775de04eee9c2f01ccef3e35673efd45a77370e61b1001a9ebde44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-win32.whl
| Download URL | touml-0.1.4-py3-none-win32.whl |
|---|---|
| Size | 1.5 MB |
| Tags | Python 3 Windows x86-32 |
|
SHA-256 checksum How to use checksums |
0d9411b9512b42bd6955e531a2cd2ed1fb7542a33be5a9b177830157e350831e
|
|
BLAKE2b-256 checksum How to use checksums |
d78787afe7063d3c47be894ba04e3da4cbb44b6b73b9e918d1cd8dc06886bffb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-musllinux_1_2_x86_64.whl
| Download URL | touml-0.1.4-py3-none-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 1.7 MB |
| Tags | Linux musl 1.2+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
9cc5c050f2adcd7346ac45c59da0183fc2ae3d5072f946a6a60ba721226c3476
|
|
BLAKE2b-256 checksum How to use checksums |
0bee3da5f4ddce395846440fce6922e4310fbf5371068d3a094062bcfbb7e894
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-musllinux_1_2_i686.whl
| Download URL | touml-0.1.4-py3-none-musllinux_1_2_i686.whl |
|---|---|
| Size | 1.7 MB |
| Tags | Linux musl 1.2+ x86-32 Python 3 |
|
SHA-256 checksum How to use checksums |
c9a4ba5a31d9187dd5b3e0e8e99d8355033e1790321536108c3b03efdf787565
|
|
BLAKE2b-256 checksum How to use checksums |
1274be06f644ec0cd70ee4cb9d2ef028411cf681cf6f2fc7d96e2bebbe471260
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-musllinux_1_2_armv7l.whl
| Download URL | touml-0.1.4-py3-none-musllinux_1_2_armv7l.whl |
|---|---|
| Size | 1.5 MB |
| Tags | Linux musl 1.2+ ARMv7l Python 3 |
|
SHA-256 checksum How to use checksums |
ee59549862cf7dfd49bf386dd8c27078fa785d978b064166d0be6a3dc6e9d524
|
|
BLAKE2b-256 checksum How to use checksums |
9d41c8f81363a033499b5c60354523a5d8c6cb88c3f0197706554acb53d5a2ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-musllinux_1_2_aarch64.whl
| Download URL | touml-0.1.4-py3-none-musllinux_1_2_aarch64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | Linux musl 1.2+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
843ba3f209d0f5dea27de11dc00750fe12cd5bd3a56723c2174d10f5c0ebaa26
|
|
BLAKE2b-256 checksum How to use checksums |
a28bf76a7fc81c3cedf95699dd5600f21703c24773dc6e46ba22cf0f29b3b451
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | touml-0.1.4-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | Linux glibc 2.17+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
0ac825b30098bcb376a3260ad18a9da9f41851100ddc3243b795017a0ee1f1f2
|
|
BLAKE2b-256 checksum How to use checksums |
614162dd9804b5f1df3b1c212b871e39a04238b9bc28e2c8bc341715bafcd72e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl
| Download URL | touml-0.1.4-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl |
|---|---|
| Size | 1.9 MB |
| Tags | Linux glibc 2.17+ IBM System/390x Python 3 |
|
SHA-256 checksum How to use checksums |
bb7dbb89fc04ff0ca78dddcc8e97c2c1f8a8b804226f309d77db20b0f6ae6ed7
|
|
BLAKE2b-256 checksum How to use checksums |
0f9bce5617f82b9cc5c00a75a14e2c835b7be2f010a954ab77b032574fcc7438
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl
| Download URL | touml-0.1.4-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl |
|---|---|
| Size | 1.8 MB |
| Tags | Linux glibc 2.17+ PowerPC 64-le Python 3 |
|
SHA-256 checksum How to use checksums |
16b254239679baa55bd03f27257478d1407275409b4c5ac166c2cd4e9e4bd80b
|
|
BLAKE2b-256 checksum How to use checksums |
93a13349488ec751bb99cc37599c7e10867e263404aa4f15cc4da4e6f19a3391
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl
| Download URL | touml-0.1.4-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl |
|---|---|
| Size | 1.7 MB |
| Tags | Linux glibc 2.17+ x86-32 Python 3 |
|
SHA-256 checksum How to use checksums |
4b76151e0351b700bb48b5c0797d2780521852e438f5bcd7680eb7d26f796fcc
|
|
BLAKE2b-256 checksum How to use checksums |
69ee7e02f71eb4d1ca3a9d8250d115f5595e875b35b166360ff11764992050ec
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl
| Download URL | touml-0.1.4-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl |
|---|---|
| Size | 1.5 MB |
| Tags | Linux glibc 2.17+ ARMv7l Python 3 |
|
SHA-256 checksum How to use checksums |
59412b8d440ec109a1204a2fa7f999c317dbda31855e424d0f7115d158f5387d
|
|
BLAKE2b-256 checksum How to use checksums |
9f96de8c5afac928bf9d2baba59ace0b2a4d19867c8e4db438fbb3719b95cbeb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
| Download URL | touml-0.1.4-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | Linux glibc 2.17+ ARM64 Python 3 |
|
SHA-256 checksum How to use checksums |
9fd4c3a7d72c590709c4df420b3c9b042dbae5bfac2683b5b49725ec8400195d
|
|
BLAKE2b-256 checksum How to use checksums |
0aa269e5c8052a8363a166ed4e8daca3de174fdd02a838d1f1939d3eed304489
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-macosx_11_0_arm64.whl
| Download URL | touml-0.1.4-py3-none-macosx_11_0_arm64.whl |
|---|---|
| Size | 1.5 MB |
| Tags | Python 3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
aa52150b136aa853e9ae2cbba4c6f5ea896c2167e1122f0cb110862e7b553e27
|
|
BLAKE2b-256 checksum How to use checksums |
b4080a86efeb9443eee501e1a65428d9b86562f6ef1bb98387d8d7af40f05fd3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|
Release files / touml-0.1.4-py3-none-macosx_10_12_x86_64.whl
| Download URL | touml-0.1.4-py3-none-macosx_10_12_x86_64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | Python 3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
9503859d675b402d394255b08b5253522e56d983c2ff34f6e03df825a16a177a
|
|
BLAKE2b-256 checksum How to use checksums |
725638b2f714215e7a7595e0f63d695cfcb60faa31a86efbc2507e83126c7164
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.8.3
|