Engine Works

Under the hood of Alteryx: tips, tricks and how-tos.
Don't forget to submit your entry for the Excellence Awards by October 30! | Need more information about the program? Check out the blog here
Alteryx
Alteryx

Fellow Alteryx Python SDK wizards, are you ready for a new spell in your spell book? This short tutorial will cover the very basics of using the Pdb module to debug your latest and greatest Python SDK tools!

 

 

https://www.demilked.com/magazine/wp-content/uploads/2016/01/colorful-spell-harry-potter-magic-books-gabriel-picolo-kun-2.jpghttps://www.demilked.com/magazine/wp-content/uploads/2016/01/colorful-spell-harry-potter-magic-books-gabriel-picolo-kun-2.jpg

 

Step 1: Make your Python SDK tool following this helpful post from @SydneyF's online grimoire:

 

 

2.png

 

 

While we are sure you are all at the top of your wizarding class, we know our tool just won’t run perfectly the first time around...let’s see how using Pdb can help!

 

 

https://i.imgflip.com/22jjt9.jpghttps://i.imgflip.com/22jjt9.jpg

 

 

Step 2: Create a workflow using your new tool, making sure to configure it with the settings you would like to test.

 

 

4 and 5.png

 

Step 3: Save your workflow to the debug_workflows folder (snakeplane > pilot > debug_workflows) with the same name as your tool (YourToolsName.yxmd); if a debug_workflows folder does not exist create one.

 

 

6.png

 

 

7.png

 

 

 

Before we continue, let’s learn a little bit about the Pdb code/commands we are going to use in our next steps (for a full list of Pdp commands, click here.😞

 

8b.png

 

 

Pro-tip: If you just hit enter, Pdp will run the last command you entered in the terminal

 

OK, let’s move on to the next step in our debugging tutorial quest...

 

 

https://www.google.com/url?sa=i&url=https%3A%2F%2Fv1.escapistmagazine.com%2Fforums%2Fread%2F7.182143-Airship-Travel-Returns-in-Final-Fantasy-Versus-XIII&psig=AOvVaw02Tl3xz1jVceaM610BizXV&ust=1585068802840000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCJDijsuHsegCFQAAAAAdAAAAABADhttps://www.google.com/url?sa=i&url=https%3A%2F%2Fv1.escapistmagazine.com%2Fforums%2Fread%2F7.182143-Airship-Travel-Returns-in-Final-Fantasy-Versus-XIII&psig=AOvVaw02Tl3xz1jVceaM610BizXV&ust=1585068802840000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCJDijsuHsegCFQAAAAAdAAAAABAD

 

Step 4: Open your main.py script in your favorite editor and insert import pdb; pdb.set_trace() where you would like to start debugging your code and click save.

 

10.png

 

 

Step 5: If you haven’t done so already, activate and freeze your environment.

 

11.PNG

 

 

Step 6: Next you will need to build your tool with the following command:
 
inv build <your_tool_name>

 

Note: every time you make changes to your main.py script you will need to rebuild your tool.

 

 

12.PNG

 

 

Step 7: Change your directory to the debug_workflows directory

 

13.PNG

 

 

Step 8: Run the workflow you created in the debug_workflows folder from the command line using the following command "C:\Program Files\Alteryx\bin\AlteryxEngineCmd.exe”

 

14.PNG

 

 

Your script will run up until the spot where you placed import pdb; pdb.set_trace(). You will know you are in the Python debugger when you see (Pdb) on the current line of your terminal.

 

15.PNG

 

 

From here we can start casting our debugging spells!

 

https://filmschoolrejects.com/wp-content/uploads/2017/04/0TuqhgxbLYZHj9lBs.jpghttps://filmschoolrejects.com/wp-content/uploads/2017/04/0TuqhgxbLYZHj9lBs.jpg

 

  • h for help: I want to see the documentation for the p command or a listing of all the documented commands:

 

17.PNG

 

 

  • p to print; pp to print-pretty: I want to see the value of an expression (e.g., a variable) in it’s current context:

 

18.png

 

 

  • q for quit: I want to quit the debugger:

19.PNG

 

This concludes the tutorial, but if you're thirsty for another mug of Pdb butter beer, check out this post by @JPKa .

 

Happy debugging Alteryx Python SDK wizards!

 

 

Comments
11 - Bolide

A helpful article @C3PO ! However, it appears the Pesky Pixies have attacked the HTML in this article. Can Hermione fix it? 🙂

Alteryx Community Team
Alteryx Community Team

no, but Late-to-the-Game wizard can!