Python
Streaming sensor data into Sift using Python
Credentials
Before starting this section be sure to retrieve your API key and the appropriate Sift URL for your provisioned environment. Instructions on how to retrieve the API key and URL and can be found in the authentication section of the documentation.
This exercise demonstrates how to stream data into Sift using the Python client library.
The objective is to read in data from a mock data source representing sensor data from our asset,
NostromoLV426
, and then stream that data to Sift.
NostromoLV426
will contain a single velocity
channel whose
values are of type double
; this channel will belong to the mainmotor
component.
For full code examples, documentation, as well as the library's source code, refer to the following:
Installing Dependencies
Before we begin streaming data to Sift we will need to install sift-stack-py. One way in which
to do that is simply to pip install
the package.
Imports
With sift-stack-py
installed, we'll begin by importing the necessary modules for this example. Inside of your main.py
:
Data Source
Next we'll define a data source that provides us mock sensor data. The data source will send a timestamp and a float
over the course of a minute, sleeping for 0.5s
between each send.
This will represent the time-series coming from the velocity
channel:
Config
Now we define the schema of our telemetry in a TelemetryConfig
which is a simple wrapper around an
ingestion config:
Client Keys
As mentioned in the ingestion config section, specifying a client key (CONFIG_KEY
in the example above) is highly recommended as it simplifies lookups for users after creation.
Sending Data
Now that we have a TelemetryConfig
, we will establish a connection to Sift, create an ingestion service, and initialize a run.
Runs are Optional
Creating a run is not required to send data to Sift. It's a mechanism to group together data for a single asset or multiple assets. Read more.
Once our ingestion_service
has successfully been instantiated, Sift will have a record of your telemetry config a.k.a. your ingestion config.
Henceforth, whenever you provide the same TelemetryConfig
with the same ingestion_client_key
, Sift will reuse that config for future streams
for the specified asset. Additional flows and channels may be added over time.
Backwards Compatibility
Note that for a given ingestion_client_key
, adding new flows and channels over time is a safe and backwards compatible operation.
Existing flows and channels, however, should not be modified; this type of change is not considered backwards compatible and will lead
to unexpected behavior.
Now that we have a fully configured ingestion service, let's read data in from our the data source we initially created and stream that data into Sift:
And that's it! In Sift, you should see the asset, NostromoLV426
, the run we just created, as well as
data for the velocity
channel.