Skip to content

Sample & solution scripts (cookbook)

Don't start from a blank file. Understand ships two trees of working scripts you can copy and adapt, and the open-source plugin repository has many more.

Where the examples live

Location What's there How you run it
plugins/Scripts/Python/ ~40 standalone Python API scripts (.py) — the main cookbook source. From a shell with upython script.py project.und.
plugins/Solutions/ Packaged plugins (.upy + helpers) for larger jobs. Install and run from the GUI — see Plugin Manager.

plugins/Scripts/Python/README.md is the getting-started note for the standalone scripts (bundled upython, or your own Python via PYTHONPATH). Under plugins/Solutions/ you'll find bigger worked solutions — git/ (Git-history analytics and ownership architectures), duplicates/ (duplicate-code detection), concurrency/ (data-race analysis), visibilityMatrix/ (dependency visibility matrix), and more.

Recipes

All standalone recipes take the database path as their argument and run with upython. The scripts live in plugins/Scripts/Python/ under your Understand install — they are not on your PATH, so run them by full path or from that directory.

List every file in a project

upython fileList.py myproject.und

fileList.py prints each project file — the smallest possible starting point for your own script.

Find dead code

upython dead_code.py myproject.und

dead_code.py reports functions/subprograms not reachable from a root (defaults to main; pass -root to change it). See also unusedEntities.py (unused entities, sortable by file or kind) and unusedFiles.py.

Export a call graph for every function

upython callGraphs.py myproject.und

callGraphs.py saves a call-graph image per function and writes an index.html gallery — a good example of driving the graph API from a script (see Write a graph plugin for the plugin form).

Dump metrics

upython projectMetrics.py myproject.und      # whole-project summary metrics
upython metrics.py myproject.und             # metrics for chosen entity kinds

For complexity specifically, funcComplexity.py (cyclomatic complexity per function) and halstead.py (Halstead measures) are good templates.

Need graphics libraries?

upython is a minimal interpreter. If a recipe needs matplotlib/pandas, run it with your own Python 3 instead — see the setup note in Python API: getting started.

Turn a recipe into a plugin

Once a script is useful, wrap it as a plugin so it runs inside the GUI without a command line — a graph (draw), report (generate), metric (value), check (check), or architecture (build). The plugins/Solutions/ folder shows this pattern end to end.