Python
When creating workflows, you'll often need to write dynamic expressions. This page provides an overview of enabling Python expressions and what functions and objects you can use.
Installing Python
Before we can use Python Expressions, we first need to have Python itself installed.
Windows
Follow these steps to install Python on Windows.
Download the Installer
Visit the official Python downloads page.
Click on the "Download Windows installer" link for the latest version.
Run the Installer
Locate the downloaded
.exe
file and double-click to start the installation.In the installer window, ensure you check the box labeled "Add Python to PATH."
Click "Install Now" and follow the on-screen instructions.
Verify the Installation
Open Command Prompt (
cmd
).Type
python --version
and press Enter.You should see the Python version number displayed.
Find the Python Installation Path
To locate the Python installation directory on Windows:
Open Command Prompt.
Type
where python
and press Enter.This command will display the path to the Python executable.
The shared library (python38.dll
) is typically located in the same directory as the Python executable.
Take note of the full path to the python38.dll
file. We will need it shortly.
MacOS
Follow these steps to install Python on MacOS.
Download the Installer
Navigate to the official Python downloads page.
Click on the "Download macOS 64-bit installer" link for the latest version.
Run the Installer
Locate the downloaded
.pkg
file and double-click to start the installation.Follow the on-screen instructions to complete the installation.
Verify the Installation
Open Terminal.
Type
python3 --version
and press Enter.You should see the Python version number displayed.
Find the Python Installation Path
Open Terminal.
Type the following command and press Enter:
This will display the path to the Python executable.
The shared library (libpython3.8.dylib
) is typically located in the lib
directory within the Python installation path.
Take note of the full path to the libpython3.8.dylib
file. We will need it shortly.
Configure Environment Variables
Make sure to configure the PYTHONNET_PYDLL
environment variable to point to the python DLL found in the previous step.
Also make sure to set PYTHONNET_RUNTIME
to coreclr
Refer to the Pythonnet GitHub project for detailed documentation.
Installing the Python Feature
The Python Expressions feature is provided by the following package:
You can enable the feature as follows:
Configuration
The UsePython
extension provides an overload that accepts a delegate that lets you configure the PythonFeature
, which itself exposes a delegate to configure PythonOptions
.
For example:
Globals
The following functions and objects are available to all Python expressions:
output
The output
object provides methods to access an activity's output.
input
variables
The variables
object provides access to the workflow variables. For example, if your workflow has a variable called OrderId, you can get and set that workflow variable using the following Python expression:
The input object provides access to workflow input.
execution_context
The execution_context object provides access to the following information:
Last updated