community
cancel
Showing results for 
Search instead for 
Did you mean: 

Alteryx Designer Knowledge Base

Definitive answers from Designer experts.

How To: Manage Metadata in the Python tool

Moderator
Moderator
Created on

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 two functions included in the ayx Python 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 retrieved or modified.

 

Prerequisites

 

  • Alteryx Designer ≥ 2018.4 

 

Procedure: Reading Metadata

 

1. Load module Alteryx from package ayx.

from ayx import Alteryx

 

2. Load input metadata with function readMetadata, 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 module Alteryx from package ayx.

 

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 the Alteryx Designer datatypes.

%DATATYPE LENGTH% : Size of the field (integer or float for Fixed Decimal of the field (note that it is called size in result window and length here)). 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
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

Moderator
Moderator

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