Runs in Nominal with Python
To use this guide, install the Nominal Python library with pip3 install nominal
.
See Quickstart for more details.
Please contact us if you’re not sure whether your organization has access to Nominal.
A Run is Nominal’s primitive for test data that shares a common time domain. This guide details common patterns for working with Runs in Python.
Connect to Nominal
To instantiate a Run, first connect to your Nominal platform tenant.
Concepts
- Base URL: The URL through which the Nominal API is accessed (typically
https://api.gov.nominal.io/api
; shown under Settings → API keys). - Workspace: A mechanism by which to isolate datasets; each user has one or more workspace, and data in one cannot be seen from another. Note that a token / API key is attached to a user, and may access multiple workspaces.
- Profile: A combination of base URL, API key, and workspace.
There are two primary ways of authenticating the Nominal Client. The first is to use a profile stored on disk, and the second is to use a token directly.
Storing credentials to disk
Run the following in a terminal and follow on-screen prompts to set up a connection profile:
Here, “default” can be any name chosen to represent this profile (reminder: a profile represents a base URL, API key, and workspace).
The profile will be stored in ~/.config/nominal/config.yml
, and can then be used to create a client:
If you have previously used nom
to store credentials, prior to the availability of profiles, you will need to migrate your old configuration file (~/.nominal.yml
) to the new format (~/.config/nominal/config.yml
).
You can do this with the following command:
Directly using credentials in your scripts
NOTE: you should never share your Nominal API key with anyone. We therefore recommend that you not save it in your code and/or scripts.
Create a Run
It’s possible to create an empty run without any data. Runs must have a start and end time expressed in absolute time. All Datasets added to the Run should overlap with this time domain.
Create a Run off of an Asset
It’s also possible to create a run off of an existing asset:
Add data to a Run
To add a Dataset to a Run, use Run.add_dataset()
:
Datasets are the file representation of Nominal’s Data Source primitive. Most often, Datasets are tabular files with at least one time dimension. Datasets can also be video files.
Head over to the Datasets page to see your organization’s most recently uploaded Datasets.
Above, we set the start and end times of the Run manually. However, you can also set the Run to span the Dataset:
Run data with ref names
To add a Dataset to a Run along with a reference name, set the ref_name
parameter in Run.add_dataset()
.
Ref names (reference names) are a namespace for data sources that share common channels, but do not necessarily belong to the same Run. They allow data sources with similar schema to be referenced as a group. For example, data sources with the same ref name can share Workbook templates and Checklists.
Check if a Run exists
You can check for a Run’s existence with client.search_runs().
Update a Run
Run metadata can be updated with Run.update()
:
For example, to set a Run’s end time to the present moment:
To update a Run’s title:
To add labels to a Run:
Please see Run.update()
for all updatable metadata.
Run attachments
File attachments such as PDF reports or PowerPoints can be added to Runs:
Retrieve a Run
Like Datasets, Runs can be retrieved by their resource ID (“RID”):
To retrieve a Run’s RID, visit its detail page and click on the clipboard icon next to “ID” in the right-hand drawer:
All Nominal primitives (eg Datasets, Runs, Workbooks, and Checks) have a unique identifier called a “Resource ID”.
Resource IDs may be referred to as “RIDs”, or simply “IDs”, throughout the platform. They can be obtained from
a primitive’s detail page (or URL) and have a format that looks like ri.catalog.cerulean-staging.dataset.e5ede17b-05f9-404d-aaf5-ba85c99761a2
.
Query Runs
Runs can be queried with client.search_runs().
For example, to retrieve all runs with the label “X-PLANE”:
See client.search_runs() for all Run search parameters.
Remove Run Data Sources
The list data_sources
can contain Connection, Dataset, Video instances, or rids as string.