We have extended our Early Bird Tickets for Inspire 2023! Discounted pricing goes until February 24th. Save your spot!

Alteryx Designer Discussions

Find answers, ask questions, and share expertise about Alteryx Designer and Intelligence Suite.
SOLVED

Run a python script in Alteryx

damiana_spadafora
6 - Meteoroid

So, this should be fairly straightforward, but for the life of me I cannot figure it out. I have a Python script and I would like to run it in Alteryx. So I am using the command tool, telling it to run cmd.exe, I am attaching my script in the command arguments box and in the read results box I have added the file to which it should write.

 

Yet when I go and run it, it opens up the command line box but nothing happens, it seems that it is not picking up the argument and running it.

 

Any idea on what I am doing wrong?

 

Thank you!!!

19 REPLIES 19
jcardoso
8 - Asteroid

Is it possible to do the other way around? Run an Alteryx workflow within a Python script? 

MacRo
Alteryx
Alteryx

@jcardoso Yes Alteryx allows you to run workflows on the command line, which you can invoke in python with something like:

 

 

import subprocess
subprocess.check_output(['C:/Program Files/Alteryx/bin/AlteryxEngineCmd.exe','C:\my_workflows\workflow1.yxmd'])

 

 

This just runs the workflow (does not return data), so you'll probably want to add an Output tool to your workflow to have Alteryx write the data you care about out to a format that you can then read in with Python (such as csv or sqlite) after the workflow execution has completed.

bobro
6 - Meteoroid

 

Any clue what an error code 1 is indicating?  I am trying to run a python script with the run command as mentioned above. 

 

Thanks

JohnPo
Alteryx Alumni (Retired)

Hi @bobro,

 

Did you check to see if the package or libraries you're installing are properly installed?

Best,
John Posada
Cloud Engineer
Raghu_s
8 - Asteroid

@michael_treadwell Hello! thanks for the write up. Few months back I used this tip to set up my .py codes running. Now, as my team gets bigger I would like to share my codes and also have it accessible so eleminating the need to recreate bigger processes. 

 

I use miniconda3 that comes by default with ALteryx and in order to make it work as expected I have to keep my scripts on the desktop only. This makes my WFs non shareable or run from a different designer installed in a desktop. 

 

Question: Do we have a possibility to call python scripts that are housed in a network aka shared folders? Spent enough time but not able to crack it. This makes me keep different version of codes at multiple places and maintain it. At times its gets messy and I lose control over the code. 

 

Any sort of help would be much appreciated. looking forward. 

 

RS 

pbrink
8 - Asteroid

I am in the same situation where I receive a "error code: 2."

 

My script file is not saved in an alteryx folder but where the file and am trying to load is at. I can run the script using my own files and folders not in Alteryx folders

You directions say to run the script in command prompt

 

with this code

So from the command prompt:

cd 'directory_of_yxmd'

'path_to_python.exe path_to_script.py --options'

 

I am unable to run this in the command prompt.

Raghu_s
8 - Asteroid

@JohnPo Thanks foe the lead. SO do I really need a server or a scheduler to do this or I can still be able to run any WF from a py code by just having a Designer in place! 

 

If that's the case can you share a sample WF and the code snippet for us to look into? 

 

Looking forward. 

 

Thanks,

Raghu 

 

 

JohnPo
Alteryx Alumni (Retired)

Hi @Raghu_s,

 

Sorry, but you can only run Python scripts that activate Designer workflows if you have a Scheduler or Server license. The reason is that if Python scripts were allowed then it would remove the necessity to use the basic tools of Server and Scheduler.

Best,
John Posada
Cloud Engineer
plundgren
6 - Meteoroid

If I may throw in a question about my own situation:

We're going to start using Python scripts to download data from our providers to fill out Excel files, then use Alteryx to combine them together into one data set before sending to our warehouse. The order of events should be this:

 

Python script executes

Alteryx reads the files and sends them to the database.

 

If I use the Run Command Tool to do this, can I be assured that it will correctly pull those events in the order required? In other words, I don't want to set up the Read Results line to pull in the final data set, only to discover it's reading data that was processed the previous day, if that makes sense. 

 

Thanks in advance.

Raghu_s
8 - Asteroid

@plundgren  It works well if the design is solid. I have codes set up a year back and it works as expected. The only catch is that you need to have administrator rights to have your packages installing in python setup inside the alteryx. Only then the codes will run as expected. if not I would suggest to use an IDE to download files in a drop zone and use the WFs to pull them later for processing. 

 

Thanks. 

Labels