Workbooks in Nominal with Python

Workbooks are Nominal’s tool for creating and sharing interactive data visualizations and analyses. They can be created directly on the Nominal platform or programmatically using the Nominal Python SDK.

Creating a Workbook from a Template

Prerequisites

If you don’t have Python installed, you can download it for free from the Python Software Foundation. We support versions 3.9 through 3.12.

To check whether Python is installed, open your shell (the Terminal application on Mac, and Command Prompt on Windows), and type python⏎. If you receive an error, you likely do not have Python installed on your machine.

The Nominal Python Client can be installed with pip:

$$ pip install nominal
Installing with Extras

The nominal client contains several opt-in features that come with their own additional, heavier dependencies. Today, these include:

  • hdf5: ingesting / working with HDF5 files
  • protos: directly streaming data to Nominal using protobuf

You may install these using, for example, pip install nominal[hdf5], or pip install nominal[hdf5,protos] for the latest version of the client. See here for more information.

Version

We use semantic versioning for the Nominal Python Client. To see the client version, run the following from within Python:

1import nominal
2
3print(nominal.__version__)
Upgrading `nominal` version

To update the version of the client installed with pip, run:

$$ pip install --upgrade nominal

As a best practice, we recommend regularly updating your client to ensure that you receive bugfixes and other improvements in a timely fashion.

Connect to Nominal

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.

Run the following in a terminal and follow on-screen prompts to set up a connection profile:

$$ nom config profile add default
>
># Alternatively, if `nom` is missing from the path:
>$ python -m nominal config profile add default

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:

1from nominal.core import NominalClient
2
3client = NominalClient.from_profile("default")
4
5# Get details about the currently logged-in user to validate authentication
6# Will display an object like: `User(display_name='your_email@your_company.com', ...)`
7print(client.get_user())

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:

$nom config migrate
>
># Or, if `nom` is missing from your path:
>python -m nominal config migrate
1from nominal.core import NominalClient
2
3# Get an instance of the client using provided credentials
4client = NominalClient.from_token("<insert api key>")
5
6# Get details about the currently logged-in user to validate authentication
7# Will display an object like: `User(display_name='your_email@your_company.com', ...)`
8print(client.get_user())

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.

  • If you trust the computer you are on, use nom to store the credential to disk.
  • Otherwise, use a password manager such as 1password or bitwarden to keep your token safe.
If you’re not sure whether your company has a Nominal tenant, please reach out to us.

Steps to Create a Workbook from a Template

  1. Obtain the Template RID:
    • Navigate to the Nominal platform.
    • Go to Workbooks ➔ Templates.
    • Click on the desired template.
    • In the top-left corner next to the template name, click the dropdown arrow ⌄.
    • Select Copy RID to copy the template RID to your clipboard.
  2. Obtain the Run RID:
    • Navigate to Runs.
    • Click on the run you want to associate with the workbook.
    • On the right side of the screen, locate the RID under “Metadata”.
  3. Create the Workbook Using the SDK:
1from nominal.core import NominalClient
2
3client = NominalClient.from_profile("default")
4
5client.create_workbook_from_template(
6 template_rid = 'your_template_rid',
7 run_rid = 'your_run_rid',
8 title = 'My new workbook',
9 description = 'This is a new workbook created from a template',
10)

Accessing Your New Workbook

After creating the workbook programmatically:

  • Navigate back to Workbooks on the Nominal platform.
  • Locate your new workbook titled “My New Workbook”.
  • Open it to view and interact with your data visualizations.