In expression mode, you can enter a valid Python expression to return the required data. The expression mode is specifically optimized to provide a smart prompt feature which simplifies your input and outperform the code mode.
Hover over any Dataway textbox, and the mode selection buttons will pop up automatically. Click Expression and then click the textbox to enter an expression.
Autocomplete
When you input content in the textbox, the Dataway interactive UI will automatically display the syntax prompts and viable completion options based on the current context below or above the textbox. You can select an appropriate tag to quickly complete your expression. The syntax prompts include attributes, methods, built-in functions, and third-party modules.
Reference on the flow data panel
In expression mode, you can reference data on the flow data panel. For more information, see Flow Data Panel.
Type conversion
Other than certain components with special requirements, the expression mode supports convenient type conversion for the Dataway interactive UI. You can click the target data type in the drop-down list on the left of the textbox to convert the type of the expression output result explicitly, so as to forcibly change the data type. The default type is any
, i.e., no type conversion.
The expression mode is based on the eval()
function in Python 3 syntax to make it easier to use. Like the code mode, the expression mode allows you to use msg
(Message
type) to reference the message of the current flow. In addition, in expression mode, you can quickly reference the output data of previous components quickly on the flow data panel.
The expression mode supports the following syntax structures:
Expression Group | Expression Type | Description | Example | Remarks |
---|---|---|---|---|
Atomic expression | literal | Literal | "abc", 123, True, b'abc' | Literal of a data type such as `string`, `int`, `float`, `bool`, or `bytes`. |
name | Identifier | abc | A variable used to read the specified name from global context. | |
tuple | Tuple | ('a', 'b', 'c'), (str(1)) | Returns a tuple if there is at least one comma; otherwise, returns the value of a single expression. | |
list | List | [1,2,3] | Enumerates elements to construct a list. | |
list-comp | List comprehension | [i for i in 'abc'] | Constructs a list through comprehension. | |
set | Set | {1,2,'a'} | Enumerates elements to construct a set. | |
set-comp | Set comprehension | {i for in 'abc'} | Constructs a set through comprehension. | |
dict | Dictionary | {1:2, 'a':'b', 3.0:True} | Enumerates elements to construct a dictionary. | |
dict-comp | Dictionary comprehension | {i:i*i for i in range(10)} | Constructs a dictionary through comprehension. | |
generator | Generator | (k*k for k in range(10)) | Returns a generator. | |
Primary expression | attr | Attribute reference | msg.payload | Returns an attribute. |
index | Container subscript value | msg.payload[1], msg.vars['a'] | Gets the value by subscript. | |
slice | Slice subscript | msg.payload[1:3] | Gets the value by subscript. | |
call | Call | str('a') | Calls a function. | |
Mathematical expression | binop | Binary operator | 3**3, 3+3, 'a' is not in msg.vars | Exponentiation (**), arithmetic operations (+, -, *, /, //, %), shift operations (>>, <<), bitwise operations (&, ^, |), and comparison operations (>, >=, <, <=, ==, !=, is, is not, in, not in) are supported. |
uniop | Unary operator | not msg.vars, ~msg.vars['no'] | `+` (keeps the value of the operand), `-` (produces the negative value), `~` (indicates bitwise negation), and `not` (indicates logical NOT). | |
Conditional expression | if-expr | Conditional expression | 'a' if 's' in msg.vars else 'b' | xx if True else xx. |
logical | Logical expression | a and b, not True | Boolean operations (`and`, `not`, `or`) are supported. | |
Special expression | dataref | Data reference | Tags generated automatically after you click data in the drop-down list | References the data in the specified path from the context. |
The expression mode fully supports the core types in iPaaS based on native types in Python. Data of types bound to the core types in iPaaS can freely flow between components and Dataway.
Data Type | Core Type in iPaaS | Feature | Feature Type | Feature Functionality | Output Type |
---|---|---|---|---|---|
int | Integer | + | Operator | Addition. | int |
- | Operator | Subtraction. | int | ||
* | Operator | Multiplication. | int | ||
/ | Operator | Division. | float | ||
// | Operator | Floor division. | int | ||
% | Operator | Modulus. | int | ||
-x | Operator | Negative value. | int | ||
& | Operator | Bitwise AND. | int | ||
| | Operator | Bitwise OR. | int | ||
^ | Operator | Bitwise XOR. | int | ||
~ | Operator | Bitwise negation. | int | ||
<< | Operator | Left shift. | int | ||
>> | Operator | Right shift. | int | ||
< | Operator | Less than. | bool | ||
> | Operator | Greater than. | bool | ||
<= | Operator | Less than or equal to. | bool | ||
>= | Operator | Greater than or equal to. | bool | ||
== | Operator | Equal to. | bool | ||
!= | Operator | Not equal to. | bool | ||
str | String | + | Operator | Concatenation. | str |
* | Operator | Repetition. | str | ||
[index] | Subscript operation | Gets the value of the specified index. | str | ||
[index1:index2] | Subscript operation | Splices the data. | str | ||
[index1:index2:step] | Subscript operation | Splices the data by step. | str | ||
in | Operator | Returns whether the data is a substring. | bool | ||
% | Operator | Formatting. | str | ||
== | Operator | Equal to | bool | ||
!= | Operator | Not equal to | bool | ||
bool | Boolean | or | Operator | OR | bool |
and | Operator | AND | bool | ||
not | Operator | NOT | bool | ||
== | Operator | Equal to. | bool | ||
!= | Operator | Not equal to. | bool | ||
float | Float | + | Operator | Addition. | float |
- | Operator | Subtraction. | float | ||
* | Operator | Multiplication. | float | ||
/ | Operator | Division. | float | ||
// | Operator | Floor division. | float | ||
% | Operator | Modulus. | float | ||
-x | Operator | Negative value. | float | ||
< | Operator | Less than. | bool | ||
> | Operator | Greater than. | bool | ||
<= | Operator | Less than or equal to. | bool | ||
>= | Operator | Greater than or equal to. | bool | ||
== | Operator | Equal to. | bool | ||
!= | Operator | Not equal to. | bool | ||
bytes | Non-core types | + | Operator | Concatenation. | bytes |
* | Operator | Repetition. | bytes | ||
[index] | Subscript operation | Gets the value of the specified index. | int | ||
[index1:index2] | Subscript operation | Splices the data. | bytes | ||
[index1:index2:step] | Subscript operation | Splices the data by step. | bytes | ||
in | Operator | Returns whether the data is a substring. | bool | ||
% | Operator | Formatting. | bytes | ||
== | Operator | Equal to. | bool | ||
!= | Operator | Not equal to. | bool | ||
list | List | + | Operator | Concatenation. | list |
* | Operator | Repetition. | list | ||
[index] | Subscript operation | Gets the value of the specified index. | any | ||
[index1:index2] | Subscript operation | Splices the data. | list | ||
[index1:index2:step] | Subscript operation | Splices the data by step. | list | ||
in | Operator | Returns whether the data is an element in the list. | bool | ||
< | Operator | Returns whether each element in the former list is less than the corresponding element in the latter list. | bool | ||
> | Operator | Returns whether each element in the former list is greater than the corresponding element in the latter list. | bool | ||
<= | Operator | Returns whether each element in the former list is less than or equal to the corresponding element in the latter list. | bool | ||
>= | Operator | Returns whether each element in the former list is greater than or equal to the corresponding element in the latter list. | bool | ||
== | Operator | Equal to. | bool | ||
!= | Operator | Not equal to. | bool | ||
dict | Dictionary | [key] | Subscript operation | Gets the value of the specified `key`. | any |
== | Operator | Equal to. | bool | ||
!= | Operator | Not equal to. | bool | ||
set | Non-core types | & | Operator | Intersection. | set |
| | Operator | Union. | set | ||
- | Operator | Subtraction. | set | ||
< | Operator | Returns whether the data is a proper subset. | bool | ||
> | Operator | Returns whether the data is a proper superset. | bool | ||
<= | Operator | Returns whether the data is a subset. | bool | ||
>= | Operator | Returns whether the data is a superset. | bool | ||
in | Operator | Returns whether the data is an element in the list. | bool | ||
== | Operator | Equal to. | bool | ||
!= | Operator | Not equal to. | bool | ||
decimal.Decimal | Decimal | + | Operator | Addition. | decimal |
- | Operator | Subtraction. | decimal | ||
* | Operator | Multiplication. | decimal | ||
/ | Operator | Division. | decimal | ||
% | Operator | Modulus. | decimal | ||
-x | Operator | Negative value. | decimal | ||
< | Operator | Less than. | bool | ||
> | Operator | Greater than. | bool | ||
<= | Operator | Less than or equal to. | bool | ||
>= | Operator | Greater than or equal to. | bool | ||
== | Operator | Equal to. | bool | ||
!= | Operator | Not equal to. | bool | ||
datetime.datetime | Date and time | year | Attribute | Year. | int |
month | Attribute | Month. | int | ||
day | Attribute | Day. | int | ||
hour | Attribute | Hour. | int | ||
minute | Attribute | Minute. | int | ||
second | Attribute | Second. | int | ||
microsecond | Attribute | Microsecond. | int | ||
+ | Operator | Moves forward the date. | datetime.datetime | ||
- | Operator | Calculates the time interval. | datetime.timedelta | ||
< | Operator | Less than. | bool | ||
> | Operator | Greater than. | bool | ||
<= | Operator | Less than or equal to. | bool | ||
>= | Operator | Greater than or equal to. | bool | ||
== | Operator | Equal to. | bool | ||
!= | Operator | Not equal to. | bool | ||
datetime.date | Date | year | Attribute | Year. | int |
month | Attribute | Month. | int | ||
day | Attribute | Day. | int | ||
strftime(format) | Method | Formatting. | str | ||
+ | Operator | Moves forward the date. | datetime.date | ||
- | Operator | Calculates the time interval. | datetime.timedelta | ||
< | Operator | Less than. | bool | ||
> | Operator | Greater than. | bool | ||
<= | Operator | Less than or equal to. | bool | ||
>= | Operator | Greater than or equal to. | bool | ||
== | Operator | Equal to. | bool | ||
!= | Operator | Not equal to. | bool | ||
datetime.time | Time | hour | Attribute | Hour. | int |
minute | Attribute | Minute. | int | ||
second | Attribute | Second. | int | ||
microsecond | Attribute | Microsecond. | int | ||
< | Operator | Less than. | bool | ||
> | Operator | Greater than. | bool | ||
<= | Operator | Less than or equal to. | bool | ||
>= | Operator | Greater than or equal to. | bool | ||
== | Operator | Equal to. | bool | ||
!= | Operator | Not equal to. | bool | ||
Entity | Binary entity | from_bytes(bs,mime_type=None, encoding="utf-8") | Static method | Constructs an `Entity` object based on the binary data. | Entity |
from_value(obj,mime_type=None, encoding="utf-8") | Static method | Constructs an `Entity` object based on the data. | Entity | ||
get(key,dafault=None) | Method | Gets the data. | any | ||
[key] | Subscript operation | Gets the value of the specified `key`. | any | ||
[^value] | Subscript operation | Gets the parsed value. | any | ||
[^blob] | Subscript operation | Gets the binary raw data. | bytes | ||
RecordSet | Data set | schema() | Method | Gets the schema. | dict |
Record | Single data record | [key] | Subscript operation | Gets the value of the specified `key`. | any |
Message | Message | payload | Attribute | Returns the output. | any |
attrs | Attribute | Returns an attribute. | dict | ||
vars | Attribute | Returns a variable. | dict | ||
id | Attribute | Returns the unique identifier of the message. | str | ||
seq_id | Attribute | Returns the flow sequence number. | str | ||
error | Attribute | Returns an error. | dict | ||
isthrowing | Attribute | Specifies whether to throw an error. | bool |
The expression mode provides various type methods, built-in functions, and third-party modules for you to choose as needed to quickly implement predefined features. For more information, see Expression Mode Appendix.
Was this page helpful?