Python as a scripting language
JavaScript is a default scripting language in Etlworks. All of the examples in this documentation were created for JavaScript.
It is, however, possible to use Python instead.
Etlworks includes a library Jython, which adds Python to the list of supported scripting languages.
Currently, Jython supports Python 2.7 and does not support loading third-party packages.
Availability of Python in Etlworks
Python is available in the following places:
- In dedicated scripting flow Execute JavaScript or Python code.
- In Mapping to calculate the field's value.
- In scripting transformations (before/after/for each row).
- When configuring conditions and loop conditions in Nested flow.
How to write scripts in Python
Step 1. Everywhere where there is a scripting text area, click the Open in Editor
button.
Step 2. Click Select Language
and choose Phyton
.
Step 3. Write code in Python.
How to import Java classes and packages into the Python script
To access the classes provided by the Etlworks Java API, you need to import a particular package and class. It is possible to import multiple packages and classes into the same Python program.
For example:
from org.jsoup import Jsoup
from com.toolsverse.etl.core.task.common import FileManagerTask
from com.toolsverse.util import TypedKeyValue, Utils
from java.util import ArrayList
// the rest of the code
The same Java packages and classes that are available from JavaScript are also available from Python.
How to return a value from the Python script
If the Python code needs to return a value, for example, when calculating a field's value on the fly or setting the loop conditions, call scriptResult.setResult(the_value_that_you_want_to_return)
.
For example:
if evals < files.size():
fileFrom = files.get(evals).getKey()
fileTo = files.get(evals).getValue() + '.xlsx'
scriptResult.setResult(fileFrom)
This is different from JavaScript were the last calculated expression is used as a return value.
Comments
0 comments
Please sign in to leave a comment.