- Open the TSM command line/shell .
-
Enter the following commands to set the host address, port values and connect timeout:
tsm security maestro-tabpy-ssl enable --connection-type {maestro-tabpy-secure/maestro-tabpy} --tabpy-host <TabPy IP address or host name> --tabpy-port <TabPy port> --tabpy-username <TabPy username> --tabpy-password <TabPy password> --tabpy-connect-timeout-ms <TabPy connect timeout>
- Select
{maestro-tabpy-secure}
to enable a secure connection or {maestro-tabpy}
to enable an unsecured connection.
- If you select
{maestro-tabpy-secure}
, specify the certificate file -cf<certificate file path>
in the command line.
- Specify the
--tabpy-connect-timeout-ms <TabPy connect timeout>
in milliseconds. For example --tabpy-connect-timeout-ms 900000
.
-
To disable the TabPy connection enter the following command
tsm security maestro-tabpy-ssl disable
Create your python script
When you create your script, include a function that specifies a pandas (pd.DataFrame) as an argument of the function. This will call your data from Tableau Prep Builder. You will also need to return the results in a pandas (pd.DataFrame) using supported data types.
For example to add encoding to a set of fields in a flow, you could write the following script:
def encode(input):
le = preprocessing.LabelEncoder()
Return pd.DataFrame({
'Opportunity Number' : input['Opportunity Number'],
'Supplies Subgroup Encoded' : le.fit_transform(input['Supplies Subgroup']),
'Region Encoded' : le.fit_transform(input['Region']),
'Route To Market Encoded' : le.fit_transform(input['Route To Market']),
'Opportunity Result Encoded' : le.fit_transform(input['Opportunity Result']),
'Competitor Type Encoded' : le.fit_transform(input['Competitor Type']),
'Supplies Group Encoded' : le.fit_transform(input['Supplies Group']),
})
The following data types are supported:
Data type in Tableau Prep Builder |
Data type in Python |
String |
Standard UTF-8 string |
Decimal |
Double |
Int |
Integer |
Bool |
Boolean |
Date |
String in ISO_DATE format “YYYY-MM-DD” with optional zone offset. For example, “2011-12-03” is a valid date. |
DateTime |
String in ISO_DATE_TIME format “YYYY-MM-DDT:HH:mm:ss” with optional zone offset. For example, “2011-12-03T10:15:30+01:00” is a vslid date. |
Note: Date and DateTime must always be returned as a valid string.
If you want to return different fields than what you input, you'll need to include a get_output_schema function in your script that defines the output and data types. Otherwise, the output will use the fields from the input data, which are taken from the step that is prior to the script step in the flow.
Use the following syntax when specifying the data types for your fields in the get_output_schema:
Function in Python |
Resulting data type |
prep_string () |
String |
prep_decimal () |
Decimal |
prep_int () |
Integer |
prep_bool () |
Boolean |
prep_date () |
Date |
prep_datetime () |
DateTime |