Write your first Labric job
Jobs are Python scripts that run in a sandboxed environment on Labric. They can be triggered automatically when files are uploaded, or run on demand. This guide walks through creating a simple job that reads a CSV and writes the data to a table.
Create a job
- Go to Jobs and click New
- Give your job a name (e.g., “CSV Importer”)
- Replace the default script with the code below
The script
This reads the first input file as a CSV, then writes every row to a table called measurements. If the table doesn’t exist, Labric creates it automatically.
Set up a trigger (optional)
To run this job automatically whenever a CSV is uploaded:
- Toggle Enable trigger in the job form
- Set the file extension filter to
.csv
The job will fire each time a matching file arrives, with the file path available as LABRIC_FILE_PATH_0.
Write modes
The mode parameter controls how data is written:
create— Insert new rows. Usebatch_insert_ok=Truefor better performance on large datasets.create-or-update— Upsert. Matches existing rows by the fields you specify inparams_to_match_for_update, updates them if found, inserts if not.
Run it
Click Execute on your job page, select a CSV file, and watch the execution log. Once it completes, your data will be available in the Data section.