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.

How To: Manage Metadata in the Python tool

PaulN
Alteryx Alumni (Retired)
Created

How To: Manage Metadata in the Python tool

Starting with Alteryx Designer 2018.4, the Python tool can now read and write metadata for better communication with the rest of the workflow. This is accomplished using twofunctions included in theayxPython library; readMetadata() and write() with the argument columns=. Like other functions related to input/output, one needs to run the workflow first in order to access data.

Remark: with 2018.4, metadata field description could not be retrievedor modified.

Prerequisites

  • Alteryx Designer 2018.4

Procedure:Reading Metadata

1. Load moduleAlteryx from packageayx.

from ayx import Alteryx

2. Load input metadata with functionreadMetadata,specifying the input name as the argument.

#this example reads the connected input #1 Alteryx.readMetadata(incoming_connection_name='#1')

In this example, we use the data set found under %ALTERYX_DIRECTORY%\Samples\en\SampleData\CompetitorLocations.tab

python_metadata_19.2.png

Procedure: Writing Metadata

1. Load moduleAlteryx from packageayx.

from ayx import Alteryx

2. Describe the metadata using the following format:

new_metadata = {'PRMSIC' : {'type' : ' Int64'}}

Structure:


{ '%COLUMN NAME%' : { 'type': '%ALTERYX DATATYPE%', 'length': %DATATYPE LENGTH%, 'source': '%DATATYPE SOURCE%', 'description': '%DATATYPE DESCRIPTION%'} }

Where :

%COLUMN NAME% : Column to change (case insensitive).

%ALTERYX DATATYPE% : One of theAlteryx Designer datatypes.

%DATATYPE LENGTH% : Size of the field (integer or float for Fixed Decimalof the field (note that it is called sizein result window and lengthhere)).Length is mandatory for string datatypes and optional otherwise.

%DATATYPE SOURCE% : Source of Alteryx data (default value: PythonTool:)

%DATATYPE DESCRIPTION% : Free field to comment field (default value: empty)

3. Write the data out with the defined metadata.

#this example writes out to output anchor 1 Alteryx.write(pandas_df=input_df,columns=new_metadata,outgoing_connection_number=1) 

Example:

AlteryxGui_2019-02-03_23-39-26.png

Comments
nakamott
8 - Asteroid

Just a quick addition: you need to run the entire workflow (not just the jupyter notebook) before attempting 

 

Alteryx.readMetadata(incoming_connection_name='#1')

 

 or else Alteryx will look for the connection in \AppData\Local\Temp

PaulN
Alteryx Alumni (Retired)

Hi @nakamott,

 

Thanks for the comment! Post will be updated accordingly.

You are correct: one needs to run the workflow first, in order to be able to access tool input/output details. Temporary data and Jupyter notebook will be stored in engine temporary path for the time of the Designer session.

Note that further details could be obtained when debug parameter is set to True.

 

Example:

 

Alteryx.readMetadata('#1',debug=True)

 

Best,

 

Paul Noirel

Sr Customer Support Engineer, Alteryx