Python Executor Tool
The Python Executor Tool lets you run Python scripts right inside Nappai. Just give it a name and any code you want to execute, and the tool will handle the rest. It’s handy for quick calculations, data transformations, or any custom logic you need on the fly.
How it Works
When you add the Python Executor Tool to a workflow, Nappai takes the Python code you provide and runs it in a safe, isolated environment. The tool captures the output of the script and returns it as a “Tool” object that can be used by other components in your dashboard. No external services are called; everything happens locally inside Nappai.
Inputs
- Debug Mode: Run the code in debug mode to get detailed error messages if something goes wrong. This helps you see exactly why a script failed.
- Tool Name: A required text field where you give the tool a unique name. This name is used to reference the tool later in the workflow.
Outputs
- Tool: The component produces a Tool object that contains the result of the executed Python code. You can pass this Tool to other parts of your workflow, such as an AI agent or a data processing step.
Usage Example
-
Drag the Python Executor Tool into your workflow.
-
Set Tool Name to “CalculateSum”.
-
In the code editor, write a simple script, e.g.:
result = sum([1, 2, 3, 4, 5]) -
Enable Debug Mode if you want to see detailed error output.
-
Connect the Tool output to the next component that needs the result, such as a display widget or an AI prompt.
The tool will run the script, return the result, and you can use it anywhere else in your dashboard.
Related Components
- PythonExecutorTool – The same component; no additional related components available.
Tips and Best Practices
- Use Debug Mode when first testing a script to catch syntax or runtime errors.
- Keep the code short and focused; long scripts can be hard to debug.
- Name your tools clearly (e.g., “DataCleanUp”, “ReportGenerator”) so you can easily identify them later.
- Avoid using the tool for heavy computations that could slow down the dashboard; use dedicated processing components instead.
Security Considerations
Running arbitrary Python code can pose security risks. Make sure you only execute trusted scripts, especially if the dashboard is shared with multiple users. Consider restricting access to the Python Executor Tool or reviewing code before running it in a production environment.