https://github.com/diceroll123/pymermaider
A Python class diagram maker compatible with Mermaid.js (and GitHub), written in Rust.
https://github.com/diceroll123/pymermaider
mermaid-diagrams mermaidjs python ruff rust rustpython
Last synced: 5 months ago
JSON representation
A Python class diagram maker compatible with Mermaid.js (and GitHub), written in Rust.
- Host: GitHub
- URL: https://github.com/diceroll123/pymermaider
- Owner: diceroll123
- License: mit
- Created: 2024-04-08T07:35:50.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-11T06:52:10.000Z (6 months ago)
- Last Synced: 2024-11-11T07:30:10.666Z (6 months ago)
- Topics: mermaid-diagrams, mermaidjs, python, ruff, rust, rustpython
- Language: Rust
- Homepage:
- Size: 143 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# pymermaider
[](https://github.com/astral-sh/ruff)
[](https://pypi.python.org/pypi/pymermaider)
[](https://github.com/diceroll123/pymermaider/blob/master/LICENSE)
[](https://github.com/diceroll123/pymermaider/actions)
[](https://pypi.python.org/pypi/pymermaider)`pymermaider` is a tool written in Rust designed to generate [mermaid.js](https://github.com/mermaid-js/mermaid) class diagrams from Python code. By analyzing Python code, `pymermaider` automatically generates mermaid.js-compatible diagrams that represent the class structures, including classes, methods, attributes, and their relationships. This tool aims to simplify the documentation process for Python projects, making it easier to visualize class hierarchies and relationships.
## Features
- **Automatic Class Diagram Generation**: Generate detailed class diagrams from Python codebases with minimal configuration.
- **Mermaid.js Compatibility**: Outputs diagrams in mermaid.js markdown syntax, ready to be embedded in your markdown documents or rendered using mermaid.js tools. GitHub supports this natively as you'll see below!## Installation
pymermaider is [available on PYPI](https://pypi.org/project/pymermaider/):
```bash
# With pip.
pip install pymermaider# With pipx.
pipx install pymermaider
```## Usage
```bash
pymermaider [OPTIONS]
```### Arguments
- ``
The path to a file or directory to process.### Options
- `-m, --multiple-files`
When processing a directory, this option will generate an individual Mermaid file for each file within the directory.- `-o, --output-dir `
Specify the output directory for the generated Mermaid files. Defaults to `./output` if not provided.- `-h, --help`
Display help information for the command.- `-V, --version`
Show the current version of `pymermaider`.### File Selection:
- `--exclude `: Excludes specific files and/or directories from being analyzed.
- `--extend-exclude `: Similar to `--exclude`, but adds additional files and directories to exclude on top of those already specified.#### Example for `--extend-exclude`:
```bash
pymermaider /path/to/dir --extend-exclude "**/tests/*,**/docs/*"
```This command will exclude any folders within the subdirectories of `/path/to/dir` that are named `tests` or `docs`.
---
### NOTES:
- Some codebases are so massive that processing the directory into one file will result in mermaid code that's too large to render. By default, it's 50,000 characters. This is a good reason for the `-m` flag. You can break class diagrams apart more easily into multiple renderings.
## Example
Given a Python file `example.py` with the following content:
```python
class Animal:
def __init__(self, name: str) -> None:
self.name = nameclass Dog(Animal):
def bark(self) -> str:
return "Woof!"
```Running pymermaider on this file will provide:
```mermaid
classDiagram
class Animal {
- __init__(self, name) None
}class Dog {
+ bark(self) str
}Dog --|> Animal
```## Future Additions
- ~~Output directory option~~ ✅
- ~~Better output file naming convention~~ ✅
- Import resolution (sorta-kinda implemented now, but not good enough or even used yet)
- More language support, maybe?? 😳🤔
- Sort classes with relationships to be grouped together
- Test suites!## Known Issues
- methods with property-setter decorators can be confusing in the output
## Contributing
Contributions are more than welcome, just make a PR and we'll go from there!
## License
This project is licensed under the MIT license. Please see the
[LICENSE](LICENSE) file for more details.