It is possible to generate sequence diagram from python code?

dmx picture dmx · Jul 21, 2017 · Viewed 7.3k times · Source

I have about 700 lines of code. I have to write a little doc about this code. In this doc, I plan to have a sequence diagram to explain a bit more. something like this: enter image description here Since Iam a bit lazy, I would like to know if there is a tool to generate this diagram from code. I don't want to lose my entire weekend doing this.

Do some have an idea that could help me?

Thanks.

Answer

Mayra Delgado picture Mayra Delgado · Jan 15, 2019

I was searching for this topic too and found the following usefull: https://github.com/bereal/pyspy

It patches the bytecode using byteplay and you can add your own callback-functions to do something before each call and after each. Similar to writting a profiler using sys.settrace but easier.

Well, I added some fixes as issue-comments because I was not able to use git properly from here. Your functions may write DLS as text, like is needed by PlantUML or ZenUML... and use it to generate your diagram.