Skip to main content

API Task - Wrangle Output to Python

Note

As of Release 9.7, Wrangle to Python conversion has been deprecated. For more information, please see End of Life and Deprecated Features.

Warning

EXPERIMENTAL FEATURE: This feature is intended for demonstration purposes only. This feature may be modified or removed from the Designer Cloud Powered by Trifacta platform without warning in a future release. It should not be deployed in a production environment.

You can enable an API endpoint that converts the your recipe steps to generate a specific output into Python Pandas code. When executed, this generated Python Pandas code applies transformations to your specified dataset and generates the specified output.

Alpha Release

This endpoint is the beginning of enabling the Designer Cloud Powered by Trifacta platform to integrate with pre-existing Python data pipelines.

This documentation provides information on how to explore the capabilities of the Designer Cloud Powered by Trifacta platform to generate Python code for your external data pipelines.

Enable

To enable generation of Python Pandas code, please complete the following:

Steps:

  1. You apply this change through the Workspace Settings Page. For more information, see Platform Configuration Methods.

  2. Locate the following setting and set it to Enabled:

    Wrangle to Python Conversion
  3. The feature is now enabled.

Limitations

  • This endpoint does not currently support multi-dataset operations.

  • The generated Python code does not yield readable columns in the output code.

  • Conversion of Wrangle script to Python code is supported for CSV files only.

v4 OutputObjects WrangleToPython Create

This section contains reference documentation on the API endpoint. This endpoint method is applied to a specified outputObject. This outputObject is the result of execution of a specific recipe (wrangledDataset). That recipe has references to its source importedDatasets and connections.

For more information on supported versions of the APIs, see https://api.trifacta.com/ee/9.7/index.html#section/Overview/Versioning-and-Endpoint-Lifecycle.

This API enables generation of Python Pandas code for the Wrangle recipe associated with an output object.

Version: v4

Terms...

Relevant terms:

Term

Description

outputObjects

An outputObject is a definition of one or more types of outputs and how they are generated. It must be associated with a recipe.

Note

An outputObject must be created for a recipe before you can run a job on it. One and only one outputObject can be associated with a recipe.

writeSettings

A writeSettings object defines file-based outputs within an outputObject. Settings include path, format, compression, and delimiters.

publications

A publications object is used to specify a table-based output and is associated with an outputObject. Settings include the connection to use, path, table type, and write action to apply.

Required Permissions

Note

Each request to the Designer Cloud Powered by Trifacta platform must include authentication credentials. See https://api.trifacta.com/ee/9.7/index.html#section/Authentication.

Request

Request Type: POST

Endpoint:

/v4/outputObjects/<id>/wrangleToPython

Request URI - Example:

/v4/outputObjects/3/wrangleToPython

Request Body:

The following defines the running environment used for the outputObject.

{
    "execution": "spark"
}

Response

Response Status Code - Success: 200 - OK

Response Body Example:

The generated response is the Python Pandas code:

{
from trifacta.transform_functions.function_definitions import Replace
import pandas as pd
import numpy as np

def run_transforms(df0=None):
  if (df0 is None):
    df0 = pd.read_csv('input.csv', skip_blank_lines=False, lineterminator='\n', dtype=str, encoding='UTF-8')
  replace1 = Replace('x', 'u', False, False)
  replace2 = Replace('x', 'u', True, False)
  replace3 = Replace('x', 'u', True, True)
  replace4 = Replace('x', '\\\\', True, False)
  df3 = pd.DataFrame({'new_column1': df0['col1'].apply((lambda x: replace1.exec(x))), 'new_column2': df0['col1'].apply((lambda x: replace2.exec(x))), 'new_column3': df0['col1'].apply((lambda x: replace3.exec(x))), 'new_column4': df0['col1'].apply((lambda x: replace4.exec(x)))})
  return df3
}

Reference

For more information , see https://api.trifacta.com/ee/9.7/index.html#operation/getPythonScriptForOutputObjectInput