- 6 Minutes to read
- Print
- DarkLight
- PDF
Python Logic Step
- 6 Minutes to read
- Print
- DarkLight
- PDF
Rivery's Python feature is enabled for Enterprise and Professional customers by default. To get access, contact your Rivery representative directly or connect with our team via the Contact Us form.
Overview
Python allows for quick and easy data manipulation.
This functionality is part of the Logic River type, which allows you to create a data transformation process using steps, variables, containers, conditions, loops, actions, and River runs in straightforward method.
Use Cases
- Transformation of data.
- Initiate analytic process (Tableau extract, Sisense Elasticube, etc.).
- Use Python to connect to APIs (not possible via Action River).
- Run a Python script to start the machine learning process.
Supported Version and Packages
Rivery currently only supports Python 3.8.4.
In the future, more versions will be supported.
Packages
By default, Rivery handles the installation of the most recent packages:
- NumPy
- Pandas
- Matplotlib
- Regex
- Requests
- wordcloud
- Scikit Learn
- Sqlalchemy
- Tableau api lib
- Tableau server client
If you wish to install another package, simply add it to the 'Install Additional Packages' section:
Installing additional packages requires the following syntax:
package-name==version
- A package that already exists in the Packages list cannot be updated or degraded.
- If the package version is left blank, the most recent version identified in
pip
will be installed. - Packages that require additional drivers or other system requirements to be installed on Linux are not supported.
Working With Variables
Dynamic variables are a feature of Python. These can be used to link Rivers, automate activities, and communicate data.
How To Use Logic River Variables
Select the 'Variables' tab in the upper right corner.
Set up a variable ('temp' is an example).
Please Note:
- To create an array, tick the 'Contains Multiple Values' box.
- If the item 'Clear Value On Start' is checked, the value of the variable will always be updated to the original value when a new River is formed, regardless of what happens to it during a River.
- Multiple variables can be defined.
- Users can encrypt sensitive values stored in River variables.
- Click Apply Changes.
- To use the variable(s), run this script:
from rivery_variables import temp
print(temp)
Run this script if you're working with numerous variables:
from rivery_variables import temp, variable2, variable3
print(temp, variable2, variable3)
- Use this script to save and overwrite the variable value (only strings):
from rivery_variables import temp
temp.save("insert here new content of variable")
- Run this script if you wish to concatenate multiple variables (only strings):
from rivery_variables import variable1, variable2
concatenated_variable = f'{variable1}_{variable2}'
- In the Logic River Variables window use square brackets to save an array as the variable's value, then check the 'Contains Multiple Values' box.
If you want to use the variable as an array, run this script (only arrays):
from rivery_variables import temp
temp.save([5,6,7,8])
Note:
When using a Multiple Value variable, you must only use square brackets to contain an array. Quotation marks (as with strings) aren't an option in this case.
- Use this script to run a loop over a variable with multiple values.
Variables:
Script:
from rivery_variables import temp, temp_Dict
for var in temp:
print(var)
for key, value in temp_Dict.items():
print(key)
print(value)
Encrypted Variables
Users have the option to encrypt sensitive data kept in River variables.
The variable's value is encrypted and hidden when the "Encrypt" option is used. In-line Python code cannot decrypt encrypted variables, and encrypted variables cannot store new values.
For further information, consult our Encrypted Variables documentation.
How To Use Environment Variables
Environment variables can be used throughout the entire platform. When it comes to Python steps, Environment variables are "read only" variables, they can only have their values changed in the "Variables" tab of the main menu, not anywhere along the River.
To use Environment Variables, follow the steps below:
Click on 'Variables' tab in the main menu.
in the upper right corner, click + Add Variable.
Add a value to the variable.
Please Note:
To create an Array, use square brackets to save it as the variable's value.
6. To use the variable(s), run this Python script:
from rivery_environment_variables import Test
print(Test)
Please Note:
If you wish to import both Environment and River variables, and a variable with the same name exists in both, only the second importing command will be carried out.
Here's an Example:from rivery_variables import Temp_Var from rivery_environment_variables import Temp_Var
Only the command "from rivery_environment_variables import Temp_Var" will be carried out.
If this is the case and the River and Environment variables actually share the same name, you can add aliases to these variables and specifically use them in that Logic step. Other logic steps won't recognize these aliases.
Here's an example:from rivery_variables import Temp_Var as Temp1 from rivery_environment_variables import Temp_Var as Temp2 print(Temp1) print(Temp2)
Environment variables in Python logic steps are "read only" variables; their values cannot be changed or saved.
Resources
Python allows for the manipulation of vast volumes of data, which is why Rivery offers 7 distinct resource types:
Each logic step is linked with a resource type, which can be found here:
Note:
Before a Python script is run, there is a one-minute server startup period.
Logs
All of the Python logs will be handled by the Logic river, which will post them to the Logic step's logs.
To get the log, perform the following:
1.Select Activity in the upper left corner.
You can also find the log in the main menu's Activities tab by searching for the name of your river.
Follow the on-screen instructions:
2.Click the arrow.
- Choose Download Logs
Note:
- Rivery does not modify the logs, therefore they will be displayed exactly as they are from the Python code.
- Python logs guidelines.
Python Pricing
The RPU (Rivery Pricing Unit) of the Python Logic step is calculated by adding the script's entire time and the quantity of network usage.
The Python Logic Step RPU (logicode_rpu) will be charged regardless of the run status of the Logic Step.
The python pricing is based on:
- Execution time of the user’s Python script (seconds)
- Server size they chose to execute the script (see below)
- Network bandwidth - 0.4 RPU for every 100MB of data transferred
Server Size | RPU per Minute | RPU per Hour |
---|---|---|
XS | 0.021 | 1.2 |
S | 0.041 | 2.5 |
M | 0.082 | 4.9 |
L | 0.165 | 9.9 |
XL | 0.329 | 19.7 |
XXL | 0.3884 | 23.304 |
XXXL | 0.492 | 29.52 |
The RPU can be found in the Logic Step Details:
- Click on Logic Steps
2. Logic Step Detalis is now available.
Recommendations
Rivery recommends the following to avoid repeated River runs and RPUs:
- Mock the variables using pytest, unittest, or other testing libraries. Run the scripts on your local Computer and check the results.
- Double-check that you've installed all of the necessary packages in the river's settings.
- It is advised to have as many logs as feasible to assist in the verification of script outcomes.
Limitations
- When naming a River Variable, avoid using the space character (" ").
The River Variable will not be saved, and the River will fail to run. - Variables could be used up to 13 MB or 1000 rows of data, whichever comes first. (This constraint applies to all logic steps, not only Python).
- Rivery CLI does not support the Python Logic step.
- The use of the
os
andsys
libraries is strictly prohibited due to security regulations, and commenting the imports for these libraries is not allowed. - Python reserved words cannot be used in Rivery as it may cause syntax errors and conflicts during River runs.
Here is a comprehensive list of all the reserved words in Python: