Introducing SnakePlane: a Better Way to Work with the Python SDK

May 30th, 2019

This article is by Sydney F and originally appeared on the Alteryx Engine Works Blog here: https://community.alteryx.com/t5/Engine-Works-Blog/Introducing-SnakePlane-a-Better-Way-to-Work-with-the-Python-SDK/ba-p/392872

 

What is SnakePlane?

SnakePlane is an abstraction layer that simplifies using the Python SDK.

If you’ve ever worked with the Python SDK, you know that the experience can be… confusing. There are lines and lines of code with unfamiliar functions. A lot of these functions are wrappers for processes conducted in the Alteryx Engine… written in C++.

SnakePlane takes the SDK code and wraps it into concise utility functions that are accessed through decorators. With SnakePlane, using the Python SDK is a much more intuitive and streamlined experience.

For example, this tool that converts Hexidecimal to Unicode with the original Python SDK:

 

Why is it called SnakePlane?

Short answer: Because it’s funny.

Have you ever wondered how the movie Snakes on a Plane was able to get approved to get made? Or how it was able to keep its goofy name? The short  answer is Samuel Jackson. Samuel Jackson saw the script, and wanted to be a part of it, and refused to do it unless the original title was kept.

Silly title. Silly movie. But clearly Samuel Jackson is awesome, and that’s what made it work.

snakes.jpg

SnakePlane is an abstraction layer wrapped around the Python SDK. Pythons are a type of snake. Planes are things that hold things inside of them (at least I am guessing that was the logical connection). SnakePlane holds the Python SDK inside of it. A + B + Samuel Jackson = SnakePlane. There you go. The only difference is that SnakePlane is not a silly thing, it just has a silly name.

How does SnakePlane work?

SnakePlane uses a framework similar to Flask. The developer uses a PluginFactory class to build their plugin, and through interfaces to the factory can specify their choice of options and custom functionality.

There are three functions that a developer must define when using SnakePlane: initialize_plugin defines the behavior that happens when the tool is initialized; process_datais where the central logic of the tool goes; and build_metadata is where you can define the schema of the tool’s output, allowing tools downstream to be configured in Designer without running the workflow.

These functions allow you to specify the Python SDK’s behavior, including whether records are read in row-by-row and processed one at a time (stream mode) or read in and processed all at once (batch mode), and if the input records are read in as a list or a pandas data frame.

Why would I want to build a Python SDK tool instead of a macro with a Python tool?

There are pros and cons to each approach (just like watching Snakes on a Plane with your elderly parents). The benefits of creating a tool with the Python SDK include typically faster processing times and a more native-like tool experience for end users. It is easy and straightforward to package a Python SDK tool as a .yxi to share with other users. Possible cons are that the Python SDK does require more familiarity with Python programming, and the pre-SnakePlane SDK was a little less than intuitive and not necessarily easy to use.

How do I get started using SnakePlane?

The first step to working with SnakePlane is to get SnakePlane Pilot (a development environment for SnakePlane) set up on your machine. A tutorial for getting SnakePlane Pilot installed on your machine can be found here.