Metadata-Version: 2.4
Name: maccha
Version: 0.1.1
Classifier: Programming Language :: Rust
Classifier: Programming Language :: Python :: Implementation :: CPython
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Multimedia :: Graphics
Requires-Dist: pytest ; extra == 'test'
Requires-Dist: tomli ; python_full_version < '3.11' and extra == 'test'
Provides-Extra: test
License-File: LICENSE
License-File: assets/fonts/NotoSansKhmer/OFL.txt
Summary: Fast Mermaid diagram renderer in pure Rust - 23 diagram types, no browser
License-Expression: MIT
Requires-Python: >=3.9
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Homepage, https://github.com/darhnoel/maccha
Project-URL: Repository, https://github.com/darhnoel/maccha

# maccha

Render [Mermaid](https://mermaid.js.org) diagrams to SVG or PNG from Python. The renderer is written in Rust and compiled into the package: no browser, no Node.js, no other Python dependencies.

```bash
pip install maccha
```

It supports Python 3.9 and newer. One wheel per platform (Linux, macOS and Windows) serves every Python version.

## Use it

```python
import maccha

svg = maccha.render_svg("flowchart LR; A-->B-->C")            # str
png = maccha.render_png("flowchart LR; A-->B-->C", scale=2)   # bytes
dark = maccha.render_png("flowchart LR; A-->B", theme="dark", background="#1e1e1e")

open("out.svg", "w", encoding="utf-8").write(svg)
open("out.png", "wb").write(png)
```

Every argument after the diagram source is keyword-only:

| Argument | Applies to | Meaning |
|---|---|---|
| `theme` | both | `None` (default), `"default"`, `"dark"`, `"forest"`, `"neutral"` or `"modern"`. Like `mmdr -t`: `None` leaves the theme to `config["theme"]`, then to the built-in default; a name wins over `config`. |
| `config` | both | A dict like the JSON file given to `mmdr -c` (`theme`, `themeVariables`, `flowchart`, ...). A diagram's own `%%{init}%%` wins over it. |
| `fonts` | both | A `maccha.Fonts(system=True, files=[], dirs=[], data=[])` to add fonts, or to ignore the system's (`system=False`) |
| `strict_fonts` | both | Raise `RenderError` if some text has no font that covers it |
| `scale` | PNG | Pixels per SVG unit; default `2.0` |
| `background` | PNG | A hex color: `"#ffffff"` (`#rgb`, `#rrggbb` or `#rrggbbaa`; `"#00000000"` is transparent). Names such as `"white"` raise `RenderError`. Default is the theme's background. |

For the same diagram, `render_svg` returns exactly what `mmdr -e svg` writes, and `render_png(src, scale=1.0)` what `mmdr -e png` writes.

## Errors and warnings

```python
try:
    maccha.render_svg("flowchart LR; A--")
except maccha.MermaidSyntaxError as e:    # a ValueError
    print(e.line, e.col, e.message)          # 1-based; col is 0 if unknown
```

- `MermaidSyntaxError`: the diagram is not valid. It has `line`, `col` and `message`.
- `RenderError`: any other failure, such as `strict_fonts=True` with missing glyphs.
- `MissingGlyphWarning`: a `UserWarning` raised through `warnings.warn` when some text has no font that covers it.

The GIL is released while a diagram renders, so threads can render in parallel.

## Fonts

A Noto Sans Khmer font (SIL Open Font License 1.1) is built in, so Khmer text renders with no font installed. For Japanese, Chinese, Korean or Thai text, the machine needs a font that covers it, or pass one with `Fonts(files=[...])`.

SVGs name their fonts but do not embed them; PNGs are drawn with the fonts that were measured.

## Links

- Source, issues and the list of all 23 diagram types: <https://github.com/darhnoel/maccha>
- Command-line tool and Rust library: `mmdr` and `maccha` (see the repository README)

MIT license. The bundled font's license is included in the wheel.

