@@ -364,16 +364,55 @@ Or from the command line:
364364python -m statemachine.contrib.diagram my_module.CoffeeOrder order.png
365365```
366366
367+ ### Text representations with ` format() `
368+
369+ You can also get text representations of any state machine using Python's built-in
370+ ` format() ` or f-strings — no Graphviz needed:
371+
372+ ``` py
373+ >> > from tests.machines.tutorial_coffee_order import CoffeeOrder
374+
375+ >> > print (f " { CoffeeOrder:md } " )
376+ | State | Event | Guard | Target |
377+ | -------- - | ------ - | ---- - | -------- - |
378+ | Pending | start | | Preparing |
379+ | Preparing | finish | | Ready |
380+ | Ready | pick_up | | Picked up |
381+
382+ ```
383+
384+ Supported formats include ` mermaid ` , ` md ` (markdown table), ` rst ` , ` dot ` , and ` svg ` .
385+ Works on both classes and instances:
386+
387+ ``` py
388+ >> > print (f " { CoffeeOrder:mermaid} " )
389+ stateDiagram- v2
390+ direction LR
391+ state " Pending" as pending
392+ state " Preparing" as preparing
393+ state " Ready" as ready
394+ state " Picked up" as picked_up
395+ [* ] -- > pending
396+ picked_up -- > [* ]
397+ pending -- > preparing : start
398+ preparing -- > ready : finish
399+ ready -- > picked_up : pick_up
400+ < BLANKLINE >
401+
402+ ```
403+
367404``` {tip}
368- Diagram generation requires [Graphviz](https://graphviz.org/) (`dot` command)
405+ Graphviz diagram generation requires [Graphviz](https://graphviz.org/) (`dot` command)
369406and the `diagrams` extra:
370407
371408 pip install python-statemachine[diagrams]
409+
410+ Text formats (`md`, `rst`, `mermaid`) work without any extra dependencies.
372411```
373412
374413``` {seealso}
375- See [](diagram.md) for highlighting active states, Jupyter integration,
376- SVG output, DPI settings , Sphinx directive, and the `quickchart_write_svg`
414+ See [](diagram.md) for all formats, highlighting active states, auto-expanding
415+ docstrings, Jupyter integration , Sphinx directive, and the `quickchart_write_svg`
377416alternative that doesn't require Graphviz.
378417```
379418
0 commit comments