📜Scripts
Last updated
Last updated
The Scripts feature is a scripting tool based on Jupyter Notebooks integrated directly into Violet. Scripts can be used to analyze data from across applications, generate reports, and interact directly with the APIs of other applications. Users can even use Violet Scripts as a scratchpad to run some quick checks.
The outputs of a Script can be saved as Violet entities and used elsewhere in the system, for example as Violet Parameters. A history of the outputs can be saved as well in order to track changes in a Script’s results based on varying inputs.
Currently, we support Python, MATLAB and Julia, with other languages on the way.
Violet Variables are variables created within a Violet Script that link to data from other parts of the Violet application. Violet Variables will always hold the latest values, ensuring that each Violet Script run generates accurate results.
For example, a user may have a Duro integration that pulls in a Payload object with a mass of 10kg. A user could create a Violet Variable within a Violet Script that links to that Payload mass. On the initial Violet Script run, this Violet Variable will compute to a value of 10. If the mass in Duro changes to 20kg, and this change gets pulled into Violet, subsequent Violet Script runs will emit results where that Violet Variable has a value of 20.
Violet Scripts can be set to run when any Violet Variables within it change, keeping the Violet Script results up-to-date at all times.
Violet Scripts can be accessed from the navigation panel.
Clicking on + New Script will create and open a new empty Violet Script. Users should give their script a unique and descriptive name in the settings panel.
A script will open with a blank text box where users can start typing their python code, which will automatically save.
To start, type in print('hello world')and hit Run Violet Script. This will execute the script and display the output in a new output window underneath the script.
To use Violet Variables, you must have other data in the system that you would like to use in a script, either through creating integrations or by creating parameters. In my example, I have created a Duro Integration that is pulling in a variety of components.
To create a Violet Variable use the reserved Violet["variable_name"] syntax within your script, where the variable_name can be replaced with the name of your choice. Variable names must be unique within each script and can only contain letters and numbers. You can use an underscore to separate words.
After creating a variable, click on the Violet Variables button to link the variable to the data of your choice. Each variable you have created will show up in this sidebar, with a link symbol next to it. Clicking on the link will open a popup that lets you search through the data in the system. Select the property you would like to link to that Violet Variable.
The selected property value will display next to the link symbol. Ensure it is correct, and link any additional variables you may have. Hit save to save the links and close the sidebar.
Hit Run Script. Your output will accurately reflect the values of each Violet Variable at the time of the run.
The Live toggle is a setting that will automatically re-run the Violet Script anytime the value of its linked Violet Variables change, as well as generate an output entity displaying the results of the script. If the output of the script is a numeric value, string, or boolean, it will be saved into a property of the entity as well. By default, this will create one output entity per Violet Script which will be updated every run with the new results if the output changes.
The Live toggle can be accessed from the top panel of the Violet Script. The output can be accessed from the Violet Script Outputs section
Example Violet Script Output:
If a Violet Script is Live, users can also choose to save the history of script outputs. This will generate a new output entity each run while preserving the older ones. A timeline of historical runs and their outputs can be viewed from inside of a Violet Script. An out-of-date entity will be tagged with This entity is not the latest revision, and cannot be used as a linked entity in parameters or as a Violet Variable. Turning off history will delete all existing history.
Subscribing to notifications on a Violet Script can let a user know when a Live script has been automatically run due to a changing Violet Variable, and the output has changed. Notifications will be shown in the notifications panel, as well as through Slack if a Slack notification is set up. Subscriptions are individual to each user.
Click on the eye in the top right corner of a script to subscribe to notifications.
As of now, all scripts are accessible to all users, as long as they have permission to all the data within them. If a script contains a Violet Variable linked to data from an integration a user does not have access to, they will also not have access to that script. We are working to implement a more tailored and comprehensive permissions model for Violet Scripts.
An initial script run after a period of inactivity may take more time to run than usual. If the Violet Scripts feature is heavily used and running slower than expected, please contact the Violet team.
Check out these examples of how to run scripts: