Scripts

Seal allows you to write and execute your own custom Python code within the platform, enabling powerful custom solutions and automations.

Scripts can contain code that can be then executed. This is useful for automating data transformation and creation.

For general information about writing code in Seal, see this page.

For example, scripts can ingest a machine output CSV file, do some data cleaning and other transformation, and store the results in Seal as Records.

Scripts enable you to transform your data in more powerful and flexible ways.

Outputting Records

To output new Records from a Script, 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:

import random
data = [
    {
        'Machine': 'XXXX',
        'Reading': random.randrange(1,100)
    },
    {
        'Machine': 'YYYY',
        'Reading': random.randrange(1,100)
    },
    {
        'Machine': 'ZZZZ',
        'Reading': random.randrange(1,100)
    },
]
records_to_create = pandas.DataFrame.from_records(data)

Note:

  • you can't return data from Scripts via the return keyword, since the Script 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.

Field Types

The columns in the dataframe are converted to fields in each Record. Seal infers the field types based on the data provided:

Data shape
Field type

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)

Title shortcut

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'.

Developing Scripts

Scripts can only be properly executed in an Instance of a Record Template. While developing the Script, 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).

Seal's AI Co-Pilot

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.

Last updated