Can Power Apps and Power Automate Run Python Code Directly?

Tested with Power Apps, Power Automate cloud flows, Power Automate Desktop, and Azure Functions guidance current on June 2026.

Power Apps and Power Automate can be part of a Python workflow, but the answer depends on where you want the Python to run. A canvas app does not run Python inside a formula. A cloud flow does not have a normal built-in “run this Python file” action. Power Automate Desktop is different: it includes scripting actions that can run Python on the signed-in Windows machine when Python is installed and available.

That distinction matters because it changes security, reliability, and ownership. A quick personal automation can use a local desktop flow. A shared business app usually needs Python behind an API, Azure Function, Azure Automation job, container, or another service endpoint that the app or flow calls.

Short answer for makers

Use Power Apps for the screen and business rules, use Power Automate for orchestration, and put Python in a place that is built to execute code. The clean design is usually:

  • Power Apps collects or displays the data.
  • A cloud flow validates the request and calls the right connector.
  • Python runs in a desktop flow only for local attended work, or in a hosted service for shared work.
  • The app receives a small, safe result instead of a raw script output.

This keeps the app easier to support. It also prevents a common mistake: putting too much logic in the button formula and then trying to make every user machine behave like a developer workstation.

Choose the Python path before you build

Canvas app logic stays in Power Fx

Power Apps formulas are written in Power Fx, not Python. That is where you handle screen state, simple calculations, validation, patching records, and user-facing logic. If the job is a lightweight filter, calculation, lookup, or conditional message, keep it in Power Fx instead of sending it to Python.

The boundary is data science, file processing, complex parsing, or code that depends on Python packages. When your app reaches that boundary, design the Python piece as a service and call it from the app through a flow or custom connector.

Desktop flows can run local Python

Power Automate Desktop is the most direct Microsoft-supported path for running a Python script. It runs on a Windows machine and can call Python as part of a desktop automation. That can be useful for a maker, analyst, or support worker who controls the machine and understands the local dependency.

The tradeoff is obvious: the script depends on that device, that Python installation, file paths, package versions, credentials, and desktop availability. If the automation must run for multiple users or in the background without a person signed in, treat a local desktop flow as a short-term or narrow-use option. Confirm the machine setup first; a local script will not become robust simply because it is triggered by a flow. If you are still setting up that path, check the local automation setup before you build the Python step.

Cloud flows should call a service

For cloud flows, Python belongs behind an HTTP endpoint or connector. Azure Functions is a common choice because it supports Python and can expose an HTTP trigger. You can also use a custom connector when the function or service should look like a normal Power Platform action.

This pattern gives you better deployment control. You can keep the Python package versions, secrets, logging, and error handling in one service instead of spreading them across users’ machines.

Power Platform workflow showing Power Apps, desktop Python, Azure Functions, and cloud flow outputs
Choose the Python execution path before you wire the app, flow, and hosted service together.

Practical setup patterns

Choose the smallest pattern that fits the job:

  1. Use Power Fx only when the work is simple app logic.
  2. Use Power Automate Desktop when one controlled Windows machine must run a local script.
  3. Use an Azure Function when a cloud flow needs Python on demand.
  4. Use a custom connector when makers need a friendly action name, clear inputs, and reusable authentication.
  5. Use a queue or database when the Python job may take longer than the app should wait.

For example, a canvas app might let a user submit a document request. A cloud flow can store the file, call an Azure Function that extracts values, and write the result back to Dataverse, SharePoint, or Excel. When the result is going to a workbook, keep that flow separate from the app screen; a separate flow that updates workbook rows is easier to test than a long button formula.

Where this changes your app design

The app should not expose a raw script path, command line, package name, or private endpoint to normal users. It should send business inputs such as a record ID, file ID, or selected option. The Python service should return only the result the user needs.

For sensitive data, add an approval point or owner review before the Python output updates a production record. Also decide who owns failures. If the flow run fails because the service returned a 500 error, the flow owner needs logs from the Python host, not just the app error message.

For desktop flows, document the user context. A script that works when you run it manually may fail when Power Automate Desktop runs under a different account, a different working folder, or a machine without the same packages installed.

Questions makers ask about Python

Can Power Apps run a Python file from a button?

Not directly inside the app formula. The button can trigger a flow, and the flow can call a service that runs Python. That keeps the app in the Power Platform permission model and keeps the executable code outside the canvas app.

Can Power Automate cloud flows run Python without Azure?

Not as a normal built-in Python script action. You need an execution host, such as Azure Functions, another web API, a custom connector, or a desktop flow running on a Windows machine. The best choice depends on whether the work is cloud-based, local-device-based, or long running.

Is Power Automate Desktop enough for business automation?

It can be enough for a controlled, attended, or machine-specific workflow. It is not ideal when many users need the same Python process or when the job must run reliably without a desktop session. In those cases, a hosted API is usually easier to monitor and secure.

Should I use Python instead of Power Fx?

Use Python when the task needs Python libraries, complex file handling, statistical logic, or an existing codebase. Use Power Fx for app interaction, simple validation, and record updates. Mixing the two is reasonable when each part has a clear boundary.

Before you build the workaround

Decide who will own the Python runtime before you design the app screen. If one analyst owns a local desktop flow, keep the automation narrow and visible. If a department depends on the result, move Python to a service with logs, deployment control, and an authentication story.

The most reliable Power Platform design is not “run Python everywhere.” It is a small Power Apps interface, a predictable flow, and a Python endpoint that does one job well.