Connections in Nominal with Python
Nominal can connect to a variety of 3rd-party API services, time series databases, and cloud file stores (e.g. S3). These connections are displayed on the Connections page of your Nominal tenant.
In addition to support for connecting to external data sources, Nominal also has its own internal time series database. This guide details how to establish a connection to this database and stream channel data to it in Python.
Connections are objects that sit on top of an underlying database connected to Nominal (Influx, Timescale, etc). Connections are not the data source itself.
This guide only covers connecting and streaming to Nominal’s internal time series database. This is the easiest and fastest way to stream data to Nominal.
To set up streaming to an external database connected to Nominal, please reach out to us in our shared Slack/Teams channel.
Streaming Data to Nominal
Prerequisites
Make sure you have the nominal Python packages installed. You can install it using:
Connect to Nominal
Get your Nominal API token from your User settings page.
See the Quickstart for more details on connecting to Nominal from Python.
Creating a Connection to Nominal’s Internal Time Series Database
You only need to run the code below to create a connection once!
Moreover, you may not even need to create a new connection if you or a
colleague has already set one up. Check the connections page
for existing connections where Type = nominal
and Status = Connected
.
To stream data to a Connection, first create a connection to Nominal’s internal time series database. The
datasource_id
must be unique within your organization, and connection_name
is a friendly name that will appear on
the Nominal platform under all connections.
You can access this connection later using its rid
. You can find the rid
in connection.rid
of the code above
or look it up on the Nominal platform in the “Connections” section and use it in the nm.get_connection() function
Streaming Data Non-Blocking to the Connection
The Nominal client provides a convenient way to write data to the connection without blocking your application during network requests, which can be slow compared to your sample rate.
Writing a Single Data Point
First, we’ll write a single data point to verify that it arrives correctly on the Nominal platform.
In this example:
channel_name
: You can choose any name for your channel.timestamp
: Can be a Python datetime object, a string in ISO format (e.g., “2024-12-31T15:00:00.001Z”), or a time in nanoseconds since the Unix epoch.
Viewing the Data Point in Nominal
After executing this code snippet, we will create a Run and a Workbook, so we can see the data point.
Creating a run
Creating a Workbook
- Navigate to the Run section on the Nominal platform.
- Locate and select your run named “my_run_name”.
- Click on “New Workbook” on the top right-hand side of the page and select “New Empty Workbook”.
- In the left pane under “Channel Search”, you should see “my_channel_name”.
- Drag and drop “my_channel_name” into the “Time Series Chart”.
- Click the play button at the top middle of the page to display the data point.
You should see the data point that written.
Streaming Continuous Data
Now, let’s stream more data points to this channel.
After running this code, you can see new data points appearing in your Workbook. To view the latest data points more effectively, select “Last Minute” in the “Time History” dropdown at the top middle of the page.
Streaming Multi-Channel Data to the Connection
The stream allows for streaming multiple channels, with different intervals simultaneously.
After executing the code above, refresh your Workbook in the browser. In the “Channel Search” section, you should now see “my_channel_name_2”. Drag and drop it into the “Time Series Chart” and click the play button at the top middle of the page to view the data.