Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Knowledge Base

Definitive answers from Designer Desktop experts.

Python Tool Libraries - An Introduction to Python

MichaelF
Alteryx Alumni (Retired)
Created

With the Python Tool, Alteryx can manipulate your data using everyone’s favorite programming language - Python! Included with the tool are a few of pre-built libraries that extend past even the native Python download. This allows you to extend your data manipulation even further than one could ever imagine. The libraries installed are listed here - and below I’ll go into a bit more detail on what and why these libraries are so useful.

Each library is well documented, and there’s usually an introduction or examples on their sites to get you started on how a basic function in their library works.

neo

ayx – Alteryx API – simply enough, we’re using Alteryx, sooo yea, kind of a requirement for the translation between Alteryx and Python.

jupyter – Jupyter metapackage – If you’ve used a Jupyter notebook in the past, you’ll notice the interface for the Python Tool is similar. This interface allows you to run sections of code outside of actually running the workflow, which makes understanding and testing your data that much easier.

http://jupyter.org/index.html

matplotlib – Python plotting package – Any charting, plotting, or graphical needs you would want will be in this package. This provides a great deal of flexibility for whatever you want to visualize.

https://matplotlib.org/

numPy – NumPy, array processing for numbers, strings, records, and objects – Native Python processes data in what some would call a cumbersome way. For instance, if you wanted to make a matrix, a.k.a. a 4x4 table, you would need to create a list within a list, which can slow processing a bit. However, NumPy has its own “array” type that fits the data in this matrix pattern that allows for faster processing. Additionally, it has a bunch of methods of handling numbers, strings, and objects that make processing a whole lot easier and a whole lot faster.

http://www.numpy.org/

pandas – Powerful data structures for data analysis, time series, and statistics – This is your staple for handling data within Alteryx. Those who have used Python, but never pandas, will enter a whole new beautiful world of data handling and structure. Data manipulation within Python is faster, cleaner, and easier to code with. The best part about it is that the Python Tool will read in your Alteryx data as a pandas data frame! Understanding this library should be one of the first things to know when tackling the Python code.

https://pandas.pydata.org/

geopandas – Extends the data types used by pandas to allow spatial operations on geometric types. Are you interested in geospatial analysis using Python? Try this package. It makes working with geospatial data in Python much easier and faster.

http://geopandas.org/

requests – Python HTTP for Humans – for all the connector/Download Tool fans out there. If any of you are familiar with making HTTP requests (API calls and the like), then you should introduce yourselves to this package and explore how Python performs these requests.

http://docs.python-requests.org/en/master/

scikit-learn – a set of Python modules for machine learning and data mining – Welcome to the world of machine learning in Python! This library is your go-to for statistical and predictive modeling and evaluation. Any crazy and wild methods you’ve learned for machine learning will most likely be found here and can really push the boundaries of data science.

http://scikit-learn.org/stable/

scipy – Scientific Library for Python – all your scientific and technical computing can be found here. This library builds off the packages already installed here, like numPy, pandas, and matplotlib. Dealing with mathematical models and formulae are usually located within this library and can help provide that higher level analysis of your data.

https://www.scipy.org/

six – Python 2 and 3 compatibility utilities – For those who are unfamiliar, Python versions come in 2 forms, version 2.x and 3.x (with 3.x being the most recent). Now, even though Python 3 is supposed to be the latest and greatest, there are still many users out there who prefer using Python 2. Therefore, integration between the two is a bit tricky with syntax differences, etc. The six module provides functions that are usable between the two so everyone can remain calm and happy! Their documentation is usually coupled with which version the functions most closely align to, so a user can get a better idea to its functionality.

https://pypi.org/project/six/

SQLAlchemy – Database Abstraction Library – SQL in Python! Covers all your database needs from connecting to and extracting data, allowing it to interact with your Python code and thus, Alteryx itself.

https://www.sqlalchemy.org/

statsmodels – statistical computations and models for Python – This library builds off sci-kit learn but focuses more on statistical tests and data exploration. Additionally, it utilizes R-style formulae with pandas data frames to fit models!

https://www.statsmodels.org/stable/index.html

These are the libraries installed with the Python Tool, which can do almost any data function imaginable. Of course, if you’re looking to do something that these libraries don’t provide, there are myriad other Python libraries that I’m sure will help you with your use case. Most of these are also well documented in how to use so search away and let your mind float away in the beautiful cosmos created by Python.

Comments
david_pinsley
7 - Meteor

Thanks for this excellent post.  Can someone direct me to where I can find documentation on the Alteryx API?

_richardr
10 - Fireball

Has anyone had any luck installing GeoPandas library using Alteryx.installPackages("geopandas") ?  I get errors and can't find workaround no matter what I do.  I would love to throw some spatial objects at Python but am held up by this library.  I was able to install Shapely library which can interact with a geopandas (http://geopandas.org/) dataframe but currently am stuck.

 

 

mayscw10
7 - Meteor
Has anyone installed packages from a mirrored PyPI repository? I have a pip.conf file that prompts me for my credentials when I install via pip on the command line in a vanilla python environment, is there a way to have Alteryx call the same function?
Atabarezz
13 - Pulsar

How to import packages from GitHub as well? any examples...

simon
11 - Bolide

If you are pushing the python tool, your site deserves a dedicated python area with more examples. It's like crickets here... 

 

Any one able to push a yxzp or its blob to Alteryx.read("#1")? 

StephenR
Alteryx
Alteryx

@simon Please check out our DevSpace. This is a more detailed conversation board for advanced users of different programming languages.

klonergan
8 - Asteroid

Can anyone clarify how python environments are managed when publishing a workflow to the server/gallery?  That is, if I have a workflow that uses the new python tool and I've installed a package using Package.installPackages(), how do I install that package on the server so that the workflow runs within gallery?  E.g., is there something like a requirements.txt file?  I thought this would maybe be embedded as a workflow asset, but that doesn't appear to be the case.  Or is there no environment management on server, and I just have to open designer on the server and install the pacakages there (and manage all packages globally - which seems like it will become an issue if the user base grows)? 

I couldn't find any documentation or community posts that specifically address this.  Thank you.  

esridhar126
7 - Meteor

Hi i tried to install ayx package, but got an error as no module found like follows,

Any one please help to install this package.

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-1-ec9eff74ca39> in <module>()
----> 1 from ayx import Alteryx

ModuleNotFoundError: No module named 'ayx'

 

 

Sam_Rathi37
5 - Atom

I tried installing teradata library using 

 

from ayx import Package
Package.installPackages(['teradata']) & Alteryx.installPackage("teradata"). Anhyone can help me with installing this package.

 

WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000000046BAE10>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/teradata/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000000046BA630>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/teradata/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000000046BA470>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/teradata/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000000046BA4E0>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/teradata/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ConnectTimeoutError(<pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at 0x00000000046BAF28>, 'Connection to pypi.org timed out. (connect timeout=15)')': /simple/teradata/
ERROR: Could not find a version that satisfies the requirement teradata (from versions: none)
ERROR: No matching distribution found for teradata
 
 
---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
<ipython-input-5-2926eb142ebc> in <module>
      2 # script here (only missing packages will be installed)
      3 from ayx import Package
----> 4 Package.installPackages(['teradata'])
      5 #Package.installPackages(['pandas','numpy'])

c:\program files\alteryx\bin\miniconda3\envs\jupytertool_venv\lib\site-packages\ayx\Package.py in installPackages(package, install_type, debug)
    200     print(pip_install_result["msg"])
    201     if not pip_install_result["success"]:
--> 202         raise pip_install_result["err"]

c:\program files\alteryx\bin\miniconda3\envs\jupytertool_venv\lib\site-packages\ayx\Utils.py in runSubprocess(args_list, debug)
    118 
    119     try:
--> 120         result = subprocess.check_output(args_list, stderr=subprocess.STDOUT)
    121         if debug:
    122             print("[Subprocess success!]")

c:\program files\alteryx\bin\miniconda3\envs\jupytertool_venv\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
    354 
    355     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 356                **kwargs).stdout    357 
    358 

c:\program files\alteryx\bin\miniconda3\envs\jupytertool_venv\lib\subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
    436         if check and retcode:
    437             raise CalledProcessError(retcode, process.args,
--> 438                                      output=stdout, stderr=stderr)    439     return CompletedProcess(process.args, retcode, stdout, stderr)
    440 

CalledProcessError: Command '['c:\\program files\\alteryx\\bin\\miniconda3\\envs\\jupytertool_venv\\python.exe', '-m', 'pip', 'install', 'teradata']' returned non-zero exit status 1.
Jan_C_Ott
6 - Meteoroid

Suggestion: add numpy-financial to standard libraries. This would allow alteryx to more completely take over Excel use for financial firms. Tools like yield are not available in alteryx but simple to use in numpy-financial.

kshivam12
5 - Atom

Useful post Thanks for sharing it that truly valuable knowledge about similar topic. Amazing. Have a more successful day. Amazing write-up always finds something interesting. Have a look  python course in pune