How to run a Python script from Power Automate
Yes, through a desktop flow. Power Automate for desktop has a Run Python script action that executes Python code and returns its output, and a cloud flow can start that desktop flow with the Run a flow built with Power Automate for desktop action.
What does the Run Python script action do?
Microsoft's scripting actions reference says it executes Python script code and retrieves its output. You give it the script text, pick a Python version, and can add folder paths where external Python modules live.
The action produces two values: PythonScriptOutput, which holds the script's output, and ScriptError, which holds any errors from the code. Python needs no special notation for new variables. To return values to the flow, use the print function.
Which Python version can it use?
The action reference lists Python 2.7 and Python 3.4 as the version choices. A Microsoft release plan page says Power Automate for desktop supports scripts written for Python 3 in addition to Python 2, with general availability on Apr 25, 2024. That page is marked archived, so check the version list in your own copy of the app.
How do you pass values in and out of the script?
As of November 2026, Microsoft's scripting reference gives these rules.
| Task | What Microsoft says |
|---|---|
| Declare a variable in Python | No special notation is needed |
| Return a value to the flow | Use the print function. The text arrives in PythonScriptOutput |
| Use a flow variable inside the script | Use percent notation, %variable%, and treat it like a hard-coded value |
| Python version default | The Python version input defaults to Python 2.7 |
| External modules | Add the folders that hold them in Module folder paths |
| Errors | ScriptError holds the errors. Exceptions listed are Failed to run Python script and Directory not found |
Does the script need admin rights?
Microsoft says Windows requires administrator rights to reach protected resources, such as some files, from scripting actions. To use them, run Power Automate with administrator rights. Microsoft's reference points to its setup page on running Power Automate with elevated rights.
How do you start the script from a cloud flow?
- Build the Python step inside a desktop flow in Power Automate for desktop.
- In Power Automate, create a cloud flow, either instant or automated.
- Add the action Run a flow built with Power Automate for desktop.
- Create the desktop flow connection if the action asks for one.
- Set the run mode to attended or unattended, and pick your desktop flow.
- Fill in any input variables, which appear as fields on the action.
What does a cloud flow need to run it?
- A registered machine or machine group to run the desktop flow.
- A work or school account and a configured desktop flow connection.
- The appropriate license for attended runs, or an unattended add-on for unattended runs. The person who created the connection needs it.
- Input data for a desktop flow is limited to 2 MB, and up to 70 desktop flow runs per minute are supported for every connection.
Where does the data go?
Input variables pass data from the cloud flow to the desktop flow, and output variables pass data back. New to flows? Read how to use Power Automate. For license questions read Power Automate license for a small team, and for premium calls read the HTTP premium connector license.
Want a flow that hands work to a script?
Al Davies builds tools that cut busywork and missed steps for teams.
FAQ
Can Power Automate run Python?
Yes. Power Automate for desktop has a Run Python script action that executes Python script code and retrieves its output.
How do I get a value back from the Python script?
Microsoft says to use the print function, and the output arrives in the PythonScriptOutput variable.
Does a desktop flow need a license?
Microsoft says triggered desktop flows need the appropriate license for attended runs or an unattended add-on for unattended runs.
How do I use a flow value inside the Python text?
Microsoft says to use percent notation, such as %variableName%, and treat it the same as a hard-coded value.
Does the script need administrator rights?
For protected resources such as some files, Microsoft says to run Power Automate with administrator rights.
Sources
- Scripting actions reference - Microsoft Learn
- Use Python v3 in Power Automate for desktop - Microsoft Learn
- Trigger desktop flows from cloud flows - Microsoft Learn