<< Back

Building an Alteryx Python SDK tool (Part II)

This is the second post exploring the Alteryx Python SDK extension module.

Adding bits of functionality:

Using as a template the very basic Alteryx Python SDK tool, I will now start to add some functionality with the objective of understanding how to handle:

  1. Multiple columns (fields).
  2. Multiple rows (records).
  3. Free Text

The ultimate goal of this v1 of the tool is to obtain a tool that will have a simple interface allowing the user to select the number of columns, the number of rows and the string to use to fill all the cells.

v1a – Multiple Columns:

Result I am after – click to enlarge

Following the recipe previously described, there are just a couple of tweaks needed, as I want a numeric spinner to set the number of columns:

  1. Add the numeric spinner widget to the ...Gui.html file. I want to add some constraints (i.e. have at least one and at most 20 columns), so these need to be defined. I find it useful to use as a template the HtmlGuiSdk tool (available in Alteryx in the “SDK examples” section) as it has multiple widgets for user interaction.
  2. Connect the value of the numeric spinner (after user interaction) with the python engine to be able to generate the required number of columns.
  3. Modify the code to push one record with the required number of records.


Two main changes:

  1. Load a numeric spinner widget inside the fieldset section:
  2. Add the constraints as a script inside the body section:

I do not know javascript, so I find quite useful to copy and modify the templates. Also,  make sure you have the correct definition in the head section:


Two main changes:

  1. Connect to the number spinner:
    1. I will be storing the value in self.n_columns:
    2. And now, getting the value from the xml:
  2. Modify the layout to define the type, name, etc. of the N columns :
  3. Modify the code to generate N columns:

With that, the first step –adding multiple columns– is finished. You can find the installer here (unzip it if you just want to have a look at its contents). Let’s add now multiple rows (records).

v1b – Multiple Rows (Records):

Result I am after — Click to enlarge

Similar to v1a, I will let the user define how many rows to add (and maybe set some safety limits inside the python code) via widget in the interface (this time, a plain “TextBox”); therefore, right there, two modifications to the existing files are needed:

  1. One to the ...Gui.html: to add the widget
    1. Fieldset:
    2. Script:
  2. One to the ...Engine.py: to retrieve the value
    1. __init__:
    2. pi_init: obtain the value and make sure it’s an integer. I’m also truncating the ouptut to 10000 records and throwing a warning message if the selected number is greater than that.

The next set of changes are also in the python module, within the pi_push_all_records method. This is where the iteration occurs (each iteration one record/row is pushed through the output anchor, then the record_creator is reset to generate and push the next record):

And…that’s it! Second step finished. The installer can be found here (unzip it if you just want to have a look at its contents).

v1 – Custom Text:

The only thing missing from the requirements is something to allow the user to define the text in each cell… I can visualize it now: a text box in the GUI, adding the string variable in the ...Gui.html and retrieving it in the ...Engine.py…It’s getting easier every time.

  1. Final Gui: added a textbox named “FreeText”, variable “FText”.
  2. Final Engine: Retrieve text from XML and run some checks, added a row & column indicator to the output so that I can visualize how Python and Alteryx process the records and fields.

    Final Engine – Click to Enlarge, then save to open.

Final version:

Final Tool – Click to enlarge

You can download the installer from here (unzip it if you just want to have a look at its contents).


All in all, still not a very useful tool, but I know now how to create one, how to modify the settings in the GUI and how to retrieve those settings in the Python Engine and push the multiple records and fields through the output anchor… Next post, I will finally get the tool I wanted from the beginning (and show how to add custom packages to the installer).

Leave a Reply

Your email address will not be published. Required fields are marked *