Writing Scripts with the Seal Module
Last updated
Last updated
The Seal Platform allows you to write and execute your own custom Python code within the platform, enabling powerful custom solutions and automations.
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, 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.
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.
To get a specific version of an entity, include the version as a second argument. You can also pass an entity ref object instead.
Since it returns the whole json blob for the entity, you can get the entity's fields via entity["fields"]
, or a specific field via entity["fields"]["fieldName"]
.
Gets the entity the script card is embedded in.
Gets (non-archived) entities by their title (string). Note that exact titles are necessary. Since multiple entities can share the same title, this returns an array.
Update a field value in the entity the script is embedded in.
Update a field value in any entity.
Add a new field to the embedded-in entity.
For specific field types, refer to this specific section in the Scripts docs.
Add a new field to any entity.
Remove a field from the embedded-in entity. Note that the field's data will also be removed.
Delete field in any entity.
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.
Extract data from a file entity. See Parameters below:
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:
Submit instances to a submission field in the surrounding entity.
Submit one or more instances to an instance submission field, with optional initial field values in a dataframe. If a column is called 'title' or 'Title', it will set the instances' titles of setting the values of a field called 'title' or 'Title').
You can optionally specify a number of empty instances to create.
You can also submit data to a submission table in any entity:
Generate a chart from an Altair chart. See parameters below:\
chart
: The Altair chart instance
title
:The name for the chart
type_title
: The name of the type to create a chart from. The content type must be Chart.
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: