The chat responses are generated using Generative AI technology for intuitive search and may not be entirely accurate. They are not intended as professional advice. For full details, including our use rights, privacy practices and potential export control restrictions, please refer to our Generative AI Service Terms of Use and Generative AI Service Privacy Information. As this is a test version, please let us know if something irritating comes up. Like you get recommended a chocolate fudge ice cream instead of an energy managing application. If that occurs, please use the feedback button in our contact form!
Skip to content
Insights Hub and Industrial IoT

Insights Hub drives smart manufacturing through the industrial Internet of Things. Gain actionable insights with asset and operational data and improve your processes.

IoT Time Series Client for Python¶

Introduction¶

The IoT Time Series Service allows you to interact with time series data related to assets. Refer to IoT Time Series for more information about the service.

Further implementation of the IOT TimeSeries SDK library has been shown in a sample project that you can download and test in local or on Insights Hub application. Please refer to this repository: industrial-iot-python-sdk-examples

Hint

In the IoT context, assets are referred to as entity and aspects as propertyset.
Placeholders in the following samples are indicated by angular brackets < >.

Time Series Operations¶

Client Name: TimeSeriesClient

Read Time Series Data¶

This code sample demonstrates how to invoke the IoT Time Series API for achieving the following behavior:

  • Read time series data for a single aspect of an asset.
  • Return data for a specified time range.
  • Return the latest value if no range is provided.
  • Return time series data for selected fields and limit.
# Import the RestClientConfig and UserToken from mindsphere_core module
from mindsphere_core import RestClientConfig
from mindsphere_core import UserToken

# Import the MindsphereError from mindsphere_core.exceptions module
from mindsphere_core.exceptions import MindsphereError

# Import the TimeseriesClient from timeseries module
from timeseries import TimeSeriesClient

# Import the GetTimeseriesRequest from timeseries.models module
from timeseries import GetTimeseriesRequest

# Create RestClientConfig and UserToken objects
config = RestClientConfig(proxy_host = "<proxy_host>", proxy_port = <proxy_port>)
credentials = UserToken(authorization = "<bearer_token>")

# Create the TimeSeriesClient object using the RestClientConfig and UserToken objects
timeseriesClient = TimeSeriesClient(rest_client_config = config, mindsphere_credentials = credentials)

try:
    # Create the request object
    request = GetTimeseriesRequest(
        _from="<start_time>",
        to="<end_time>",
        entity="<entity>",
        propertysetname="<property_set_name>"
    )

    # Initiate Get Timeseries API call
    timeseries = timeseriesClient.get_timeseries(request)

except MindsphereError as err:
    # Exception Handling

Read Latest Time Series Data¶

Read the latest uploaded value of time series data for a single aspect of an asset.

# Create the TimeSeriesClient object as shown above

try:
    # Create the request object
    request = GetTimeseriesRequest(
        entity="<entity>",
        propertysetname="<property_set_name>"
    )

    # Initiate Get Timeseries API call
    timeseries = timeseriesClient.get_timeseries(request)

except MindsphereError as err:
    # Exception Handling

Write Time Series Data¶

Write time series data for a specific aspect of an asset. This overwrites existing time series data.

Note

The maximum size of a write payload is 1 MB.

# Create the TimeSeriesClient object as shown above

try:
    time_series_data = Timeseries()
    time_series_data.time = "<time_value>"
    time_series_data.fields = {
        "<aspect_variable_1>": <value_1>,
        "<aspect_variable_2>": <value_2>,
        "<aspect_variable_3>": <value_3>,
        "<aspect_variable_4>": <value_4>
    }

    # Create the request object
    request = PutTimeseriesRequest(
        timeseries=[time_series_data],
        entity="<entityId>",
        propertysetname="<property_set_name>"
    )

    # Initiate Put Timeseries API call
    timeseriesClient.put_timeseries(request)

except MindsphereError as err:
    # Exception Handling

Delete Time Series Data¶

Delete time series data from an aspect of an asset within a given time range. This also deletes data for all variables within an aspect.

Note

Only data of up to 6 months can be deleted at once.

# Create the TimeSeriesClient object as shown above

try:
    # Create the request object
    request = DeleteTimeseriesRequest(
        _from="<start_time>",
        to="<end_time>",
        entity="<entity_id>",
        propertysetname="<property_set_name>"
    )

    # Initiate Delete Timeseries API call
    timeseriesClient.delete_timeseries(request)

except MindsphereError as err:
    # Exception Handling