Scripts
Last updated
Last updated
Seal allows you to write and execute your own custom Python code within the platform, enabling powerful custom solutions and automations.
Scripts is the umbrella term for objects that can contain and run code in Seal - the specific object types are:
This page documents functionality common to all types of Scripts.
If this is your first time using Python, then there are great reference materials online such as: https://docs.python.org/3.10/tutorial/
What if I don't know how to code?
Not to worry - Seal comes with a built in AI Copilot to write code for you. Navigate to the 'Copilot' tab on the right hand side, and start chatting with the AI to describe what you need.
The AI agent has access to your current code, as well as the surrounding procedure or run if you're coding a Script Step or Record, so you can ask it to help you debug specific issues or add to the existing code.
Once you're happy with the code, click on 'Accept code' to use it in your Script.
Note that the generated code may not fully be fit for your purpose - we recommend checking over the results.
The Seal module is a Python package for interacting programatically with the Seal platform.
It is automatically available in every Script's Python environment - you don't need to import it manually. The Seal module consists of a collection of methods on the seal
object:
Returns the entire json blob of data for that entity. The entity id can be copied from the entity's URL in Seal - it's the final section of the url, after the entity title.
Just passing an entity_id
returns the latest version or draft of the entity.
To get a specific version of an entity, include the version as a second argument.
Get entities by their title (string). Note that exact titles are necessary. Since multiple entities can share the same title, this returns an array.
Returns an array of the records in a specific previous step.
relative_index
(optional) is the nth step before the script step. If not specified, it defaults to the immediately preceding step.
Get all records produced by a specific Step entity. Returns an array of Record entities.
The file is downloaded to the local filesystem of the virtual machine instance. The value returned is the local file path as a string.
Returns the id of the new File Entity in Seal
Parameters:
file_entity_id
: ID of the file entity to extract data from
version
: (Optional) Specific version of the file entity
prompt
: (Optional, keyword-only) Custom prompt to guide the data extraction
Returns: json
Example:
Everything in Seal is an entity. Entities are self contained blobs of JSON data that conform to our schema.
Types of entities include procedures, runs, steps, records, documents, files and computed views.
All entities share these common fields:
status
fieldAll entities also have a top level status
field. There are two types of entity lifecycle that define the possible status
values - continuous and completable.
Procedures, Steps, Documents and Computed Views all have continuous lifecycles - they are designed to be reused and improved over time. Continuous entities have numbered versions - the version number increases every time you publish a new version.
Runs and Records have completable lifecycles - they represent a discrete piece of work carried out at a specific time, and therefore are usually not modified once they've been finished. If mistakes are identified, you can make a new revision of the completable entity.
Steps are reusable templates which describe how to carry out a piece of work and how to record the results. There are two types of Steps - Data Steps and Script Steps.
Data Steps contain a recordConfig
field, which describes the shape of Records that it will make when being carried out in a Run. They also contain page content (document content) that will be copied into each created Record - this is where you put instructions, images, charts etc describing how to carry out the work.
Procedures allow you to assemble a series of Steps into a larger reusable sequence of work.
Procedures contain a stages
field which contains its array of steps:
A Run represents a specific execution of a Procedure at a point in time, e.g. the specific run of some repeatable lab work that a technician did on 29/10/2024.
When executed in a Run, Data Steps can produce one or multiple Records, and Script Steps can also optionally produce Records.
There are two types of Records - Data Records and Script Records. Data Steps produce Data Records, Script Steps produce Script Records (and also optionally Data Records).
Data Records contain fields
and pageContent
- they are instantiations of Data Steps.
Script Records contain:
Data Steps and Data Records can have Fields to contain data, usually inputted by a technician while doing a Run of a Procedure, or populated by a Script for automations. Fields have unique names (within that Entity), and a specifc data types.
Fields are stored in the entity blob as an object called fields
, keyed by the unique field names. Every field object has the following fields:
id
- a unique UUID given to every field, so it can be referenced. When a Data Record is created from a Data Step, it will have the same fields with matching id
s
the field's type
the field's dataType
(usually the same as the type, but multiple field types may use the same underlying data type). type
is how it appears in the UI, dataType
refers to the underlying data type
value
- the actual data. All field values are nullable - they are usually null in Data Steps (unless you want a default value for produced Records), and then populated in Data Records when a lab technician is doing data entry, for example.
config
- certain field have additional config, for example specifying a number display format, or whether the field can contain multiple values.
For example:
Description: Numeric value.
Value: A valid JSON number or null
.
Config:
Description: Text.
Value: A string or null
. The string must be at least length 1 - to represent an empty value, use null
.
Config: None
Description: True/false.
Value: A JSON boolean or null
.
Config: None
Description: A date in ISO 8601 format.
Value: An ISO date string or null
Config: None
Description: A datetime in ISO 8601 format, requiring a timezone.
Value: A timezone aware ISO datetime string or null
Config:
Description: An array of enum-like strings. Displayed in the UI as a dropdown/select field with multiple options.
Value: An array of strings.
Config:
Description: An entity reference field for referencing other entities (of any kind), including File entities for referencing files.
Value: An array of {id, version}
objects.
Config:
Description: Lookups allow you to pull out field values from referenced entities. Useful for additive data building across steps. The value from the other entity is copied into the lookup field.
Value: Whatever the looked-up value is.
Config:
Seal comes with many common Python packages pre-installed. If there are other python packages you regularly require, please contact Seal support.
These packages are automatically imported in every Script, so don't need to be manually imported:
altair
(also aliased as alt
)
Chart
(alias of altair.Chart
)
pandas
(also aliased as pd
)
To temporarily install a package when running the script: