
Python Generated Sequence Diagrams - lipeltgm
https://dragonquest64.blogspot.com/2020/05/python-generated-sequence-diagrams.html
======
bobthepanda
Neat!

What text->diagram tools do you guys prefer? I am partial to PlantUML:
[https://plantuml.com/](https://plantuml.com/)

~~~
achamayou
Mermaid ([https://mermaid-js.github.io/](https://mermaid-js.github.io/)) is
excellent, easy to embed inline in Markdown or reStructuredText and to version
with the rest of the documentation.

~~~
guiambros
Returning 404; seems the index.html is missing; direct link:

[https://mermaid-js.github.io/mermaid/](https://mermaid-js.github.io/mermaid/)

------
motohagiography
As a security guy, this python seq diagram view would be super valuable as
essentially a markup language for BAN logic for documenting encryption and key
management schemes.

[https://en.wikipedia.org/wiki/Burrows%E2%80%93Abadi%E2%80%93...](https://en.wikipedia.org/wiki/Burrows%E2%80%93Abadi%E2%80%93Needham_logic)

Oddly, I've never heard this called "security protocol notation" before, but
apparently that's a thing as well.
[https://en.wikipedia.org/wiki/Security_protocol_notation](https://en.wikipedia.org/wiki/Security_protocol_notation)

------
jianyuan
Diagram as Code:
[https://github.com/mingrammer/diagrams](https://github.com/mingrammer/diagrams)

------
rgoulter
While it's good to see the results you can get from familiarity with
imagemagick drawing commands and a small script,

for more sophisticated scenarios (or customisation), you can still get
"rendered from text on my computer" using tools like PlantUML. (Or GraphViz
for graphs, etc.).

Embedding the resulting diagrams in the text editor (like Emacs' org-babel
allows for) makes for a nice diagramming experience.

~~~
lipeltgm
Agreed and for a few years now that's what I have done. But for detailed,
log/debug driven sequence diagrams that often required parsing a log,
generating a compliant text-input to the tools followed by submitting to the
tool and exporting the graphic. This 30-minute project is a step in the
direction to fully automate the process.

------
karlicoss
Nice! I did something similar for my personal infrastructure map [0]. I tried
different tools, and each of them was too limited so landed on graphviz + a
python DSL [1] to generate the diagram.

It turned out to be _extremely_ convenient:

\- python makes it easy to spot errors/typos (you can use mypy even before
running the genrator)

\- keyword arguments and dictionaries map naturally to node/edge properties

\- you can reuse boilerplate by using functions, variables and control
structures

\- you can always inject graphviz string directly as a last resort hacking
measure

\- thanks to python's dynamic features, you can even give the nodes/clusters
same names as their corresponding python objects, which results in less
boilerplate and makes easy to debug

[0] [https://beepb00p.xyz/myinfra.html](https://beepb00p.xyz/myinfra.html)

[1]
[https://github.com/karlicoss/myinfra/blob/master/generate.py](https://github.com/karlicoss/myinfra/blob/master/generate.py)

~~~
ris
When needing to do something similar (with our pseudo-microservice project's
increasingly incomprehensible JSON logs) I also wanted the diagram to be
interactive so it's possible to "dig" when showing larger amounts of data, so
I learned d3.js and was _very_ pleasantly surprised by the power of the
abstraction it introduces, despite the unavoidable javascript.

[https://github.com/alphagov/digitalmarketplace-
logdia](https://github.com/alphagov/digitalmarketplace-logdia)

(ended up having to turn it into a custom WebExtension just so it could
integrate "easily" with kibana by monkeypatching & intercepting its xhr
requests, let's not get into that...)

------
wegs
Neat!

What I really wish for is integration, or at least discovery.

I run into posts like this all the time, see neat things, and then can never
find them again.

I like all-in-one libraries like pylab/matplotlib where I know where to look.
The corollary is that if this could be folded into something, it'd probably
see more use. But I'm not sure what.

Or perhaps an alternative might be to have all libraries like this categorized
in some way. I'm not quite sure how, though.

------
seesawtron
Is anyone else struggling to run it? I keep getting the error at line 67:

ValueError: invalid literal for int() with base 10: ''

Changed it to float before int casting but still the same error.

~~~
lipeltgm
What value are you encountering for list 'D' when you get the error? As you
can see from the code, not really production-grade coding and certainly not
heavily tested, proof-of-concept more than anything else.

~~~
seesawtron
I tried running it with jupyterlab. I had issues with executing imagemagick
commands which is why the temp.jpg file didn't get created causing the error
(list D is empty).

------
th5
AsciiFlow.com !

Not text to diagram, but creating diagrams in text that I check-in to the
comments at the top of my code.

------
bbrik
Very cool. Why all those semi-colons in your code?

~~~
lipeltgm
I doubt it'll be a popular response, but despite Python not requiring
semicolons while many do (or most languages I use), I simply tend to end all
statements with semicolons as a personal preference.

