Python Plugin
Use a Python script to process pipeline data.
Use Python Plugin to process images or results from earlier modules, calculate a custom inspection result, or pass new data to later blocks.

Writing a script
Open the Plugin module in the pipeline. Enter a name in Name and write your code in the script editor, which suggests available commands and data keys.
Use Save to save the script in the module. To reuse it in other pipelines, select Save to codebase. To load a saved script, select it from the Codebase menu.
Reading and exporting data
Use Data.get() to read a result from an earlier block and Data.export() to pass a result to later blocks:
score = Data.get("AnomalyDetection_0.pred_score")
Data.export("score", score)
Use the actual ID of the module that produced the data. If the Python Plugin ID is PythonScript_0, the exported value in this example is available as PythonScript_0.score. Choose an export name without dots that does not match an input key. To set compliance, use Data.set_compliance() instead of exporting a value named compliance.
Example: setting compliance
This script uses the score from an Anomaly Detection module and sets the result using the constants already available in the script: COMPLIANT, UNCERTAIN, and DEFECTED. Adapt the module ID and thresholds to your inspection.
score = Data.get("AnomalyDetection_0.pred_score")
if score < 0.3:
verdict, compliance = "PASS", COMPLIANT
elif score < 0.7:
verdict, compliance = "REVIEW", UNCERTAIN
else:
verdict, compliance = "FAIL", DEFECTED
Data.export("verdict", verdict)
Data.set_compliance(compliance)
print(f"Verdict: {verdict} (score: {score})")
Results and errors
After testing, open the module to see exported data and image previews. The Action Plan console shows messages from print() and any script errors.
The script runs in a separate environment isolated from the main application. If the script raises an error, the application keeps running, but the error stops the pipeline: later blocks do not run.