Select to view content in your preferred language

Create flow chart from python script

144
6
Wednesday
ShareUser
Esri Community Manager

Does anyone know if there is a way to generate flow chart (or flow diagram) of python scripts?  I would like to use something that is supported by the modules available in ArcGIS Pro's Package manager so I don't break anything.  In a perfect world, I'd be able to take existing scripts and either include them in a list to create a diagram from, or a directory of scripts, etc.  I have a bunch of scripts I have created and being able to graphically see the logic/flow of potential options would be incredibly helpful to see what will happen where/when.  I've been searching and reading for several days on this and trying to find a viable solution.

0 Kudos
6 Replies
DanPatterson
MVP Esteemed Contributor

untested by me, but most recommended online

pyflowchart · PyPI


... sort of retired...
0 Kudos
TimDe_Troye
Occasional Contributor

Thank you Dan - I did see multiple references to pyflowchart, but it's not in ArcGIS Pro's Package Manager as  available options.  I was thinking that loading something in to the cloned virtual environment that is not listed in the Package Manager would not be a good idea due to potential conflicts or messing up the cloned environment.  Am I mistaken in that?

0 Kudos
DanPatterson
MVP Esteemed Contributor

make a clone of the arcgispro-py3 environment and pip install it there

Package Manager—ArcGIS Pro | Documentation

it is a long information filled link so read on


... sort of retired...
HaydenWelch
MVP Regular Contributor

Are you talking about making a flowchart in Python? Or making something similar to Model Builder's graphical programming? If it's the latter, you will need to create a new environment and include a package like Ryven unless you want to just implement all that yourself.

 

You can also create a toolbox and just use Model Builder with your own tool functions which isn't too difficult as long as you properly implement the wrapper object code

0 Kudos
TimDe_Troye
Occasional Contributor

Hayden - what I'd like to do is generate a flow chart of one or more of my python scripts so I can visually see how the code flows and what functions are to be run in what order.  I'd like to be able to regenerate the flow chart whenever I want, such as after doing major edits on a given script.  I created a basic idea of it below...

HaydenWelch
MVP Regular Contributor

You can probably use networkx which is in the standard acpy environment to build a graph, then visualize it using pyplot. You can also use the standard ast library to introspect your script and see all the relationships.

I've also just used requests to post runs with info to a database that I then inspect using external dataviz. That's useful if you want to log runs for a tool that's being used in production.

0 Kudos