Script Steps
Last updated
Last updated
Script steps are steps that contain code that is then executed during a run of a procedure. This is useful for automating data transformation and creation.
For general information about writing code in Seal, see the Scripts docs
For example, a Script step can ingest a machine output CSV file, do some data cleaning and other transformation, and store the results in Seal as Records.
Script steps enable you to transform your data in more powerful and flexible ways.
Executing the Script Step in a Run
Once in a Run and the Script Step is active, clicking '▶️ Run' will execute the code and generate a preview of the results - but no new records are actually created. This allows you to check that the results are as expected, and then mark the Step as done (just like other Steps) - this then creates the records.
To output new Records from a Script Step, assign a pandas dataframe to the special variable records_to_create
. Records generated from the script will be linked to the corresponding Step. For example:
Note:
you can't return data from Script Steps via the return
keyword, since the Script Step itself is not a Python function. Also, the final expression isn't automatically returned - it's not like Juypter Notebooks. To output record data, you must use the records_to_create
variable.
To throw exceptions, use normal Python `raise` syntax, don't put error messages in record fields in records_to_create
.
The columns in the dataframe are converted to fields in each Record. Seal infers the field types based on the data provided:
a number or None
NUMBER
a boolean
BOOLEAN
an ISO date string
DATE
an ISO datetime string (must be timezone aware)
DATETIME
any other string
STRING
an array of UUID strings
UPLOAD (i.e. an array of File ids)
an array of non-UUID strings
SELECT (a select field aka dropdown)
an array of {id, version} objects
REFERENCE (an entity reference field)
If the column name is 'title' in the dataframe, Seal will automatically output this as the title of the Record, rather than creating a field called 'title'.
Script Steps can only be properly executed in a Run of a Procedure. While developing the Script Step, you can run it in a sandboxed preview mode to check your code for bugs - no output data will be persisted (caution: side effects in your code, like uploading a file, will be persisted).
Certain features won't work in preview mode, mainly seal.get_previous_step_records()
, since that relies on there being a step above.
Seal comes with a built in AI agent to write the code for you. Navigate to the 'Co-pilot' tab on the right hand side, and start chatting with the AI to describe what you need. The AI is also able to de-bug and add to your existing code.
Note that the generated code may not fully be fit for your purpose - we recommend checking over the results.