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 agent to write 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 agent is also able to look at your current code, so you can ask it to help you debug 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:
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
.
Script Records contain:
Seal comes with many common Python packages pre-installed. If there are other python packages you 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
)
Description | Variable / Function |
---|---|
Getting entities
seal.get_entity(
entity_id
)
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. get_entity()
will return the latest version of the entity.
Getting a specific version of an entity:
seal.get_entity(
entity_id, version
)
Getting entities by their title:
seal.get_entities_by_title(
title
)
Note that exact titles are necessary. Since multiple entities can share the same title, this returns an array.
Get records from a preceding step in the run
seal.get_previous_step_records(
?relative_index
)
where relative_index is the nth step before the script step
Note that the n is optional. If not specified, it defaults to the immediately preceding step.
Get all records produced by a specific step
seal.get_step_records(
step_id
,
?step_version
)
Get a file from the file store
seal.download_file(
file_id
)
The file is downloaded to the local filesystem of the virtual machine instance. download_file()
returns the file path as a string.
Upload a file to Seal
seal.upload_file(
file_path, file_name
)
. Returns the id of the file in Seal