Python Engine SDK

Last modified: July 06, 2020

Python Engine SDK

VERSION

Current

Use the Alteryx Python SDK extension module to write custom Alteryx plugin tools, while accessing core elements of the AlteryxEngine framework.

When you create a custom tool with a Python back end, you will need to work with an SDK. For this reason, we assume you are familiar with Python and Python dependencies.

Python Tools on Server

To use a Python SDK tool that is installed on an Alteryx Server, the workflow or app must be set to Run Mode: Unrestricted. See Server Gallery Workflows or contact your Alteryx Server admin.

Encryption on Server

User Encryption:

  • Cannot Be Used with Remote Servers
  • Not Portable to Other Users

Machine Encryption:

  • Cannot Be Used with Remote Servers
  • Can Only Be Decrypted on the Same Machine (or Server)
  • Does Not Require User Credential
  • Recommended for scheduling and uploading to local instances of Alteryx Analytics Gallery.

Python Installation

Run the Python executable found in your Alteryx installation location. The following commands assume the installation location is C:\Program Files\Alteryx\bin\Miniconda3\python.exe.

Run these commands:

cmd
  1. import os, sys
  2. os.environ['PATH'] = r'C:\program files\Alteryx\bin;' + os.environ['PATH']
  3. sys.path.insert(1, r'C:\program files\Alteryx\bin\plugins')
  4. import AlteryxPythonSDK

You should now be able to use the Python SDK.

SDK Use

Python SDK Environment

The Alteryx Python SDK is not designed to run in a standalone Python environment—it is invoked by the AlteryxEngine as part of an Alteryx workflow by initializing an embedded Python process that is specifically designed for interfacing with plugin modules. The Alteryx Python SDK is compiled to run on Python version 3.6.0 that is part of the Miniconda install currently included as part of the Alteryx Designer installation.

To use the Python SDK when you create your tool's back end, you need to create a Python file. The name should relate to the tool name, and the file needs to be saved in the tool folder.

\MyNiftyPlugin\MyNiftyPluginEngine.py

This file needs to use data gathered from the data stream and manipulate the data in accordance with the user input from the tool's GUI. It is recommended that you create the front-end first to connect to the tool's data items. If you have not already created the front end, see HTML GUI SDK or Macro.

To start the design of an Alteryx Python SDK plugin module, import the Alteryx Python SDK extension module at the beginning of your script.

Python
  1. import AlteryxPythonSDK

The main body of the script is implemented in the AyxPlugin class. The AlteryxEngine requires the AyxPlugin class when it runs your script. If you do not have the AyxPlugin class, or it is not named correctly, an attribute error exception occurs.

Python
  1. AttributeError: module '__main__' has no attribute 'AyxPlugin'

Additional classes are necessary depending on what you are creating. See Classes for an overview. See Data to manage data as records.

Python SDK Tools in Iterative and Batch Macros

Global variables do not reset between iterations in iterative or batch macros. The global variables will retain their value between iterations and need to be initialized directly by the Python SDK tool. Resetting global variables should happen in the __init__ method of the AyxPlugin class.

Import Additional Libraries 

To ensure these dependencies do not conflict with any other tools in your workflow, use a virtual environment so each tool operates as a self-contained unit. See Virtual Environment and Dependencies. If using a virtual environment, a different process is required for packaging the tool as a .yxi. See YXI Packaging and Installation.

To see an example of successful implementation of a plugin, navigate to bin\HtmlPlugins\PythonSDKExample.

Was This Helpful?

Running into problems or issues with your Alteryx product? Visit the Alteryx Community or contact support.