Skip to main content

Python

Apply a simple single-line python command. For more complex python use a custom function. Note, this evaluates the python command - be especially cautious including variables from untrusted sources within the command string. The python command will be evaluated once for each row and the result returned. Reference column values by using their name. Non-alphanumeric characters within column names are replaced by underscores (_) Additionally, all columns are available as a dict named kwargs. Additional parameters set for the wrangle will also be available to the command.

The Python wrangle executes simple Python commands inline within a recipe. Row values are referenced by column name and commands are evaluated once per row. Spaces within column names are replaced by underscores (_). All columns are also available as a dictionary named kwargs. For more complex Python, use custom functions.

caution

This wrangle evaluates the Python command. Be cautious when including variables from untrusted sources in the command string.

Parameters​

NameDescriptionAccepted ValuesDefaultRequired
I/O
outputName or list of output column(s). To output multiple columns, return a list of the corresponding length.string, array—Yes
inputName or list of input column(s) to filter the data available to the command. Useful in conjunction with kwargs to target a variable range of columns. If not specified, all columns will be available.string, integer, array, nullnullNo
Options
commandPython command. This must return a value. Note: any non-alphanumeric characters in variable names are replaced by underscores (_).string—Yes
Conditions
ifCondition that determines whether the wrangle runs as a whole. Recipe variables may be referenced with ${variable}.string—No
whereFilter rows before applying the wrangle using SQL-like criteria, such as column1 = 123 OR column2 = 'abc'.string—No
where_paramsValues used with where for parameterized criteria. Uses SQLite placeholder syntax such as ? or :name.array, object—No
Errors
exceptValue to return for the row if an exception occurs during the evaluation. If not provided, an exception will be raised as normal. If multiple output columns are specified, this must match the length.string, array, number, integer, boolean, object—No

Examples​

wrangles:
- python:
output: result
command: My_Column.upper()
My Column
example text
result
EXAMPLE TEXT

The Python wrangle supports parameters so values of unknown origin can be injected safely.

wrangles:
- python:
output: sliced
command: input_column[:i]
i: ${var}

No sample available.

No sample available.

Access
RequirementValue
AI-poweredNo
Requires WrangleWorks accountNo
Requires subscriptionNo
Requires external API keyNo
Technical details
FieldValue
Catalog ID85
Catalog keypython
Recipe keypython
Catalog statusactive
Lifecycle statusactive
Recipe Writer eligibleYes
NamespaceRoot-level
Documentation groupcompute
AliasesNone
Runtime symbolwrangles.recipe_wrangles.main.python
Legacy UUIDc0398a11-7731-4e47-8df0-b07eea0b1d6c

Sources