Code

Ylem is a no-code solution but as with every modern no-code solution, you still can write code if you want to:-)

From time to time you need to resort to complex data transformations. Say a single filter is not enough, so you can write custom Python 3.9 code with a full range of features over your data work.

This is what a "Code" task is for. It has an input as JSON, with which you can do whatever you want.

Let's say that we have the following dataset and see what we do with it.

Filtering

The simplest example can be achieved by using the "Filter" block. But what if we need more complex filtering?

Let's filter out rows of a type "invoice" that have an "amount" less than 2000:

result = []

for i in input:
  if i["amount"] is not None and i["amount"] < 2000 and i["type"] == "invoice":
    result.append(i)

input = result

The result of the workflow above

Aggregation

Let's calculate the total amount:

total = 0

for i in input:
  if i["amount"] is not None:
    total += i["amount"]

input = {
  "total": total
}

Transformation

total = 0

for i in input:
  if i["amount"] is not None:
    total += i["amount"]

input = {
  "items": input,
  "total": total
}

Use Pandas

Yes, the "Code" supports Pandas framework. This is how you can work with it and the input dataset:

Limitations

Our Python processor is based on RestrictedPython, therefore the "Code" task supports many standard Python libraries but not all of them. Let us know if you want to use something that is missing and we'll be happy to add it.

Currently supported Python-modules

  • json

  • re

  • time

  • datetime

  • pandas

Last updated