Python Tool

The Python tool is a code editor for users of Python. Proficiency in Python is recommended before using this tool.

Python support

While Designer accepts custom Python code, Alteryx does not provide support for it.

Gallery compatibility

This tool is on the Alteryx Analytics Gallery list of prohibited tools. Apply for an exemption to publish a workflow containing this tool to gallery.alteryx.com.

The Python tool includes the following more common data science packages:

  • ayx: Alteryx API
  • jupyter: Jupyter metapackage.
  • matplotlib: Python plotting package.
  • numpy: NumPy, array processing for numbers, strings, records, and objects.
  • pandas: Powerful data structures for data analysis, time series, and statistics.
  • requests: Python HTTP for Humans.
  • scikit-learn: A set of Python modules for machine learning and data mining .
  • scipy: SciPy, Scientific Library for Python .
  • six: Python 2 and 3 compatibility utilities.
  • SQLAlchemy: Database Abstraction Library.
  • statsmodels: Statistical computations and models for Python.

Additional package installation

Depending on what version of Designer you're using, you can install additional packages using Alteryx.installPackages. The example below installs keras.

Alteryx.installPackages("keras")
  • Alteryx non-admin installations can install packages without any special permissions.
  • Alteryx admin installations must be run in admin mode. If you are unable to run your admin installation in admin mode, you cannot install additional packages.

You cannot use existing Jupyter Notebooks with the tool.

Connect inputs

The Python tool accepts multiple inputs. Once inputs are connected, you must run the workflow to cache the incoming data streams.

To access an incoming data connection:

  1. Import the Alteryx library: from ayx import Alteryx
  2. Access the connection and provide a variable to use a data reference:
    • Use the connection name: Alteryx.read("<connection name>")
    • from ayx import Alteryx
      data1 = Alteryx.read("#1")
    • Read in all connections and referencing the returned 0-index array: Alteryx.read(Alteryx.getIncomingConnectionNames()[<index number>])
    • from ayx import Alteryx
      data2 = Alteryx.read(Alteryx.getIncomingConnectionNames()[1])

Configure the tool

Run your workflow before beginning to work with the Python tool. Running your workflow caches your data and makes it accessible to the Python tool. Your data is then treated as a pandas data frame. More information about pandas data frames can be found at pandas.pydata.org.

Jupyter Notebook resources

The configuration window interface resembles a Jupyter Notebook. If you are unfamiliar with Jupyter Notebooks, go to Help > User Interface Tour or Help > Notebook Help. For code assistance, see the additional references that are available under the tool's Help option.

Best practices

  • Saving regularly guarantees your code is maintained when you click away from the configuration window. It also provides a checkpoint to revert to if needed. To revert, select File > Revert to Checkpoint and select the checkpoint.
  • Create a cell that prints the connection's data to the tool's results window, and leave the cell at the end of your cell list. This guarantees that you present final data in the results window.
  • print (data1)
  • If you click off the tool before changes have been saved, a JavaScript Confirm window asks "Is it OK to leave/reload this page?". Click Cancel, return to the tool's configuration window., and select Overwrite in the Notebook dialog. This allows you to save without losing the changes.

Output data from tool

Use Alteryx.write to output data from the tool.

  • To send data to other tools on the canvas, use Alteryx.write(<pandas data frame>, <output anchor number>).
    Alteryx.write(df,1)
  • Alteryx.write only accepts pandas data frames. If you have data in another format, use the pandas library to convert it to a pandas data frame. The pandas library is pre-installed with Designer and can be accessed in the Jupyter notebook using import pandas.
  • You can send up to five data frames to the output anchors.