das.iot_client.interfaces package
Submodules
das.iot_client.interfaces.assets_client module
- class das.iot_client.interfaces.assets_client.AssetsClient
Bases:
objectMethods
get_all_assets([templates, event_types])Get all assets for the organization.
get_asset_template([template_id, template_name])Get details of an asset template in IoT-TICKET.
Get a list of asset templates in IoT-TICKET.
get_assets([asset_id, asset_name, names_path])Get information of assets in a certain position of the asset tree.
get_attributes([asset_id, asset_name, ...])Read asset attributes information.
print_asset_tree([asset_id, asset_name, ...])Get all available assets printed in a tree form.
- get_all_assets(templates=None, event_types=None)
Get all assets for the organization.
- Parameters
- templatesbool
Whether to include asset template ids in the response.
- event_typesbool
Whether to include active event type for assets in the response
- Returns
- [Asset]
All assets for the organization as a list of Asset objects.
- get_asset_template(template_id=None, template_name=None)
Get details of an asset template in IoT-TICKET.
Exactly one of template_id or template_name must be provided.
- Parameters
- template_idstr
Id of the template to get info from.
- template_namestr
Name of the template to get info from.
- Returns
- dict
Asset template information as a dict including the keys ‘id’, ‘name’ and ‘attributes’.
- Raises
- ValueError
If template with the given name isn’t found.
- Exception
If there are multiple templates with the given name.
- get_asset_templates()
Get a list of asset templates in IoT-TICKET.
- Returns
- [AssetTemplate]
All asset templates for the organization as a list of AssetTemplate objects.
- get_assets(asset_id=None, asset_name=None, names_path=None)
Get information of assets in a certain position of the asset tree.
At most one of asset_id, asset_name or names_path can be given. If none of these parameters are given, root level assets are returned.
- Parameters
- asset_idstr
Optional parent asset id for which child assets in the assets tree are read.
- asset_namestr
Optional parent asset name for which child assets in the assets tree are read. This requires that in the whole asset tree the given name is unique. Otherwise asset_id or names_path must be used.
- names_path[str]
List of strings containing the path to wanted asset for which child assets in the assets tree are returned. For example to get the child assets of an asset in the path root_asset/another_asset, this parameter should be given in the form of [‘root_asset’, ‘another_asset’].
- Returns
- [Asset]
Asset information in the wanted location of the asset tree as a list of Asset objects.
- Raises
- Exception
If more than one of parameters asset_id, asset_name and names_path was given.
- get_attributes(asset_id=None, asset_name=None, names_path=None, attribute_type=None)
Read asset attributes information.
Exactly one of asset_id or asset_name or names_path must be provided.
- Parameters
- asset_idstr
Id of the asset to read attributes from.
- asset_namestr
Name of the asset to read attributes from. This requires that in the whole asset tree the name is unique. Otherwise asset_id or names_path must be used.
- names_path[str]
List of strings containing the path to wanted asset. For example an attribute of an asset in the path root_asset/child_asset/wanted_asset should be in the form of [‘root_asset’, ‘child_asset’, ‘wanted_asset’].
- attribute_typestr
Optional asset attribute type filter. One of AssetEvent, Calculated, DeviceEvent, Number, String or TelemetryData.
- Returns
- [AssetAttribute]
Attributes under the selected asset as a list of AssetAttribute objects.
- Raises
- Exception
If a wrong number of parameters asset_id or asset_name or names_path was given.
- ValueError
If attibute_type parameter had wrong value.
- print_asset_tree(asset_id=None, asset_name=None, names_path=None)
Get all available assets printed in a tree form. This method doesn’t return anything.
At most one of asset_id, asset_name or names_path can be given. If none of these parameters are given, asset tree is printed starting from the root level.
- Parameters
- asset_idstr
Optional parent asset id to print assets only from below the given asset.
- asset_namestr
Optional parent asset name to print assets only from below the given asset.
This requires that in the whole asset tree the name is unique. Otherwise asset_id or names_path must be used.
- names_path[str]
List of strings containing the path to wanted asset for which child assets in the assets tree are printed. For example to print the child assets of an asset in the path root_asset/another_asset, it should be in the form of [‘root_asset’, ‘another_asset’]
- Raises
- Exception
If more than one of parameters asset_id, asset_name and names_path was given.
das.iot_client.interfaces.commands_client module
- class das.iot_client.interfaces.commands_client.CommandsClient
Bases:
objectMethods
get_command_details([names_path, ...])Read asset's latest command log entry details.
send_command([payload, template_variables, ...])Trigger a command for a command attribute.
send_control_command(desired_value[, ...])Trigger a control command for a command attribute.
- get_command_details(names_path=None, asset_name=None, asset_id=None, identifier_name=None, timestamp='datetime', tz=None)
Read asset’s latest command log entry details. The attribute identifier name can be given to read command details from attributes with that identifier name. Note that multiple attributes can have the same attribute identifier name, and the latest details are always fetched.
Either the names_path parameter or asset_id or asset_name parameter must be given.
- Parameters
- names_path[str]
List of strings containing the path to wanted asset. For example an attribute of an asset in the path root_asset/child_asset/wanted_asset should be in the form of [‘root_asset’, ‘child_asset’, ‘wanted_asset’].
- asset_namestr
Name of the asset that the wanted command attribute is in. The asset_name parameter can only be used if it is unique in the asset tree. If this parameter is given, it must be paired with the attribute_name or the attribute_id parameter.
- asset_idstr
Id of the asset that the wanted command attribute is in. If this parameter is given, it must be paired with the attribute_name or the attribute_id parameter.
- identifier_namestr
Optional asset attribute identifier name. If not provided get latest entries from all command attributes in the asset.
- timestampstr, default=’datetime’
Optional: In which form to give the timestamps. Must be either ‘datetime’ or ‘epoch’, default is ‘datetime’. The ‘epoch’ option gives epoch milliseconds. If ‘epoch’, the tz parameter is redundant as epochs are not aware of the timezone.
- tzstr
Optional: Timezone in the form of ±[hh]:[mm], ±[hh][mm], or ±[hh]. Defaults to UTC (‘+00:00’). The data in IoT-TICKET is in UTC, if user wants the data in some other timezone, it can be determined here. Note that the timestamps seen in IoT-TICKET are shown as converted to your local timezone.
- Returns
- [SimpleCommandLogData]
Command details from the selected asset as a list of SimpleCommandLogData objects.
- Raises
- Exception
None or multiple of the parameters names_path, asset_name or asset_id were given.
- send_command(payload=None, template_variables=None, names_path=None, asset_name=None, asset_id=None, attribute_name=None, attribute_id=None, aggregated=False)
Trigger a command for a command attribute.
Either the names_path parameter or ids or names for the asset and attribute must be given and either the payload or templated_variables parameter must be given.
- Parameters
- payload
Command payload. Should be used only when the command attribute payload type is Dynamic.
- template_variablesdict
Dict of command template variable keys and values. Should be used only when the command attribute payload type is Templated. Example: {“VAL_input1”: 1,”VAL_input2”: “some string”}
- names_path[str]
List of strings containing the path to the wanted attribute that is of type Command. This parameter should be given e.g. in the form of [‘root_asset’, ‘another_asset’, ‘command_attribute’].
- asset_namestr
Name of the asset that the wanted command attribute is in. The asset_name parameter can only be used if it is unique in the asset tree. If this parameter is given, it must be paired with the attribute_name or the attribute_id parameter.
- asset_idstr
Id of the asset that the wanted command attribute is in. If this parameter is given, it must be paired with the attribute_name or the attribute_id parameter.
- attribute_namestr
Name of the wanted command attribute. If this parameter is given, it must be paired with the asset_name or the asset_id parameter to locate the attribute.
- attribute_idstr
Id of the wanted command attribute. If this parameter is given, it must be paired with the asset_name or the asset_id parameter to locate the attribute.
- aggregatedbool, default=False
If True, command will be sent to the given asset and all its sub assets.
- Raises
- Exception
For a wrong combination of locator or payload/variable parameters or if no Command attributes were found in the given asset or path.
- send_control_command(desired_value, names_path=None, asset_name=None, asset_id=None, attribute_name=None, attribute_id=None, skip_first_command=False)
Trigger a control command for a command attribute.
Either the names_path parameter or ids or names for the asset and attribute must be given
- Parameters
- desired_value
The desired target value.
- names_path[str]
List of strings containing the path to the wanted attribute that is of type Command. This parameter should be given e.g. in the form of [‘root_asset’, ‘another_asset’, ‘command_attribute’].
- asset_namestr
Name of the asset that the wanted command attribute is in. The asset_name parameter can only be used if it is unique in the asset tree. If this parameter is given, it must be paired with the attribute_name or the attribute_id parameter.
- asset_idstr
Id of the asset that the wanted command attribute is in. If this parameter is given, it must be paired with the attribute_name or the attribute_id parameter.
- attribute_namestr
Name of the wanted command attribute. If this parameter is given, it must be paired with the asset_name or the asset_id parameter to locate the attribute.
- attribute_idstr
Id of the wanted command attribute. If this parameter is given, it must be paired with the asset_name or the asset_id parameter to locate the attribute.
- skip_first_commandbool, default=False
If True, will skip sending the first command. Command will be re-sent later if desired value has not been set.
- Raises
- Exception
For a wrong combination of locator parameters or if no Command attributes were found in the given asset or path.
das.iot_client.interfaces.credentials_client module
- class das.iot_client.interfaces.credentials_client.CredentialsClient
Bases:
objectMethods
get_credential_query([organization_id, ...])Query credentials by given information.
get_credentials([organization_id])Read credentials information.
- get_credential_query(organization_id=None, credential_id=None, credential_name=None, client_id=None, scope=None)
Query credentials by given information.
Note that this method is only available for users with Subscription Owner role in IoT-TICKET.
- Parameters
- organization_idstr
The organization to get information from.
- credential_idstr
Id of the credential.
- credential_namestr
Name of the credential.
- client_idstr
Id of the client.
- scopestr
Scope of the credential.
- Returns
- dict
credential’s details as a dict with the following keys: id, name, description, grantType, accessTokenUrl, scope, clientId, organization, subscription, updatedBy, createdBy, updatedAt, createdAt.
- get_credentials(organization_id=None)
Read credentials information.
Note that this method is only available for users with Subscription Owner or Organization Admin or Designer role on IoT-TICKET.
- Parameters
- organization_idstr
The organization to get information from. Default is the IoTClient’s default organization_id.
- Returns
- credentials[Credential]
All credentials for this user.
das.iot_client.interfaces.data_client module
- class das.iot_client.interfaces.data_client.DataClient
Bases:
objectMethods
get_multiple_timeseries([names_path, ...])Get data from multiple Telemetry Data or Calculated attributes with the same call.
get_statistics(period, dimension[, ...])Read asset attribute statistics values.
get_timeseries([names_path, attribute_id, ...])Read asset attribute values from a single Telemetry Data or Calculated attribute.
get_timesignal(timesignal_id[, ...])Read asset timesignal attribute values.
write_calculated(data[, names_path, ...])Write to IoT-TICKET's Calculated attributes.
write_static(data[, attribute_ids, ...])Write to IoT-TICKET's static String or Number attributes.
write_telemetry(data, device_id, ...[, ...])Write data to a device in IoT-TICKET.
write_timesignal(device_id, device_username, ...)Write a time signal to a device in IoT-TICKET.
write_timesignals(device_id, ...[, tz])Write one or multiple time signals to a device in IoT-TICKET based on the complete payload given by the user.
- get_multiple_timeseries(names_path=None, asset_name=None, asset_id=None, attribute_ids=None, attribute_type=None, start_time=None, end_time=None, chronological_order=False, limit=10000, form='DataFrame', astype=<class 'str'>, timestamp='datetime', tz=None)
Get data from multiple Telemetry Data or Calculated attributes with the same call.
Exactly one of names_path, asset_name, asset_id or attribute_ids must be provided. Using different parameters, the user can determine how to get data (see Parameters section).
For dataframes, information of the data source will be added. It can be found in the df.attrs[‘sources’].
Which information is stored in the dataframe ‘sources’ is dependent on which information the user provides for this method. If attribute_ids is provided, only attribute_ids can be saved. If asset_id, asset_name or names_path is given, also attribute_names, device_ids and asset_path are saved. Here, asset path is the path of names to the asset that is the point in the tree that data is returned under.
- Parameters
- names_path[str]
List of strings containing the path to an asset. All data under this asset in the whole tree will be returned, subassets included. First name must be the root level asset. For example an asset in the path root_asset/parent_asset/child_asset should be in the form of [‘root_asset’, ‘parent_asset’, ‘child_asset’]. If there are empty attributes in this asset or its subassets, they are ignored.
- asset_namestr
Name of the asset to get the data under. Data from all attributes directly under this asset will be returned. If there are empty attributes in this asset, they are ignored.
- asset_idstr
Id of the asset to get the data under. Data from all attributes directly under this asset will be returned. If there are empty attributes in this asset, they are ignored.
- attribute_ids[str]
Ids of the attributes to get data from. If any of the given attributes is empty, an exception will be raised.
- attribute_typestr
Optional attribute type filter to be used with names_path, asset_name or asset_id parameter. Will only get data from attributes of this type under the asset given. Can be one of ‘Telemetry Data’ or ‘Calculated’. For both types, use None (default).
- start_timeint or str or datetime
Optional query start time, defaults to zero. If int, given in epochs. If str, given in ISO8601 format.
- end_timeint or str or datetime
Optional query end time, defaults to current time. If int, given in epochs. If str, given in ISO8601 format.
- chronological_orderbool, default = False
Optional chronological order parameter. Defaults to False. Use False to read measurements in descending order (newest is on top) and True to read measurements in ascending order (oldest is on top) by timestamp.
- limitint, default = 10000
Optional: Maximum number of measurements to read per attribute. The default value is 10000.
- formstr, default=’DataFrame’
Optional: In which form to return the fetched data. Must be one of ‘json’ or ‘DataFrame’, default is ‘DataFrame’. If ‘DataFrame’, multiple time series will be returned in separate columns. If ‘json’, the name of the respective telemetry will be the dict key.
- astypetype, default=’str’
Optional: In which type to give the data. Default is str, and in that case no conversions are done.
- timestampstr, default=’datetime’
Optional: In which form to give the timestamps. Must be either ‘datetime’ or ‘epoch’, default is ‘datetime’. If ‘epoch’, the tz parameter is redundant as epochs are not aware of the timezone.
- tzstr
Optional: Timezone in the form of ±[hh]:[mm], ±[hh][mm], or ±[hh]. Defaults to UTC (‘+00:00’). This will not affect the start_time and end_time parameters. The data in IoT-TICKET is in UTC, if user wants the data in some other timezone, it can be determined here. Note that the timestamps seen in IoT-TICKET are shown as converted to your local timezone.
- Returns
- datadict or pd.DataFrame
The fetched data.
- Raises
- Exception
If either multiple or none of the attributes names_path, asset_name, asset_id or attribute_ids were given. If one of the attributes was empty when attribute_ids was given.
- ValueError
If an ineligible value was given for the form or timestamp parameter.
- TypeError
If an ineligible value was given for the astype parameter.
- get_statistics(period, dimension, names_path=None, attribute_id=None, start_time=None, end_time=None, limit=None, timestamp='datetime', tz=None)
Read asset attribute statistics values.
Exactly one of names_path or attribute_id parameter must be provided.
Start and end times are required parameters when period selection is Custom, for other period selections those are ignored.
- Parameters
- periodstr
Statistics value period: The time span from which the statistics are calculated. Available values: CurrentMoment, CurrentDay, PreviousDay, CurrentWeek, PreviousWeek, CurrentMonth, PreviousMonth, CurrentQuarter, PreviousQuarter, CurrentYear, PreviousYear, Custom (case-sensitive).
- dimensionstr
Calculated values dimension: How to group values into bins. Available values: Minute, Hour, Day, Week, Quarter, Month, Year (case-sensitive).
- names_path[str]
List of strings containing the path to the wanted attribute. For example, an attribute of an asset in the path root_asset/parent_asset/child_asset should be in the form of [‘root_asset’, ‘parent_asset’, ‘child_asset’, ‘attribute_name’].
- attribute_idstr
Attribute id to read statistics from.
- start_timeint or str or datetime
Required query start time, when period selection is Custom, ignored otherwise. If int, given in epochs. If str, given in ISO8601 format.
- end_timeint or str or datetime
Required query end time, when period selection is Custom, ignored otherwise. If int, given in epochs. If str, given in ISO8601 format.
- limitint
Optional maximum number of measurements to read, maximum and the default value is 10000.
- timestampstr, default=’datetime’
Optional: In which form to output the timestamps. Must be either ‘datetime’ or ‘epoch’, default is ‘datetime’. If ‘epoch’, the tz parameter is redundant as epochs are not aware of the timezone.
- tzstr
Optional: Timezone in the form of ±[hh]:[mm], ±[hh][mm], or ±[hh]. Defaults to UTC (‘+00:00’). This will not affect the start_time and end_time parameters. The data in IoT-TICKET is in UTC, if user wants the data in some other timezone, it can be determined here. Note that the timestamps seen in IoT-TICKET are shown as converted to your local timezone.
- Returns
- list
A list of dicts containing the keys stattime, count, sum, avg, min and max.
- get_timeseries(names_path=None, attribute_id=None, start_time=None, end_time=None, chronological_order=False, limit=10000, form='DataFrame', astype=<class 'str'>, timestamp='datetime', tz=None)
Read asset attribute values from a single Telemetry Data or Calculated attribute.
Exactly one of attribute_id or names_path must be provided.
For dataframes, information of the data source will be added. It can be found in the df.attrs[‘sources’]. This can help the user keep track of the data’s origins.
Which information is stored in the dataframe ‘sources’ is dependent on which information the user provides for this method. If attribute_ids is provided, only attribute_ids can be saved. If asset_id, asset_name or names_path is given, also attribute_names, device_ids and asset_path are saved. Here, asset_path is the path of names to the asset that is the point in the tree that data is returned under.
- Parameters
- names_path[str]
List of strings containing the path to the wanted attribute. The first name must be the root level asset and last name the wanted attribute name. For example an attribute in the path root_asset/parent_asset/child_asset should be in the form of [‘root_asset’, ‘parent_asset’, ‘child_asset’, ‘attribute_name’].
- attribute_idstr
Id of the attribute to get data from.
- start_timeint or str or datetime
Optional query start time, defaults to zero. If int, given in epochs. If str, given in ISO8601 format.
- end_timeint or str or datetime
Optional query end time, defaults to current time. If int, given in epochs. if str, given in ISO8601 format.
- chronological_orderbool, default = False
Optional chronological order parameter. Defaults to False. Use False to read measurements in descending order (newest is on top) and True to read measurements in ascending order (oldest is on top) by timestamp.
- limitint, default = 10000
Optional: Maximum number of measurements to read, the default value is 10000.
- formstr, default=’DataFrame’
Optional: In which form to return the fetched data. Must be one of ‘json’ or ‘DataFrame’, the default is ‘DataFrame’.
- astypetype, default=str
Optional: In which type to give the data. Default is str, and in that case no conversions are done.
- timestampstr, default=datetime
Optional: In which form to give the timestamps Must be either ‘datetime’ or ‘epoch’, default is ‘datetime’ If ‘epoch’, the tz parameter is redundant as epochs are not aware of the timezone.
- tzstr
Optional: Timezone in the form of ±[hh]:[mm], ±[hh][mm], or ±[hh]. Defaults to UTC (‘+00:00’). This will not affect the start_time and end_time parameters. The data in IoT-TICKET is in UTC, if user wants the data in some other timezone, it can be determined here. Note that the timestamps seen in IoT-TICKET are shown as converted to your local timezone.
- Returns
- datadict or pd.DataFrame
The fetched data. If dataframe, it contains only two columns: timestamp and value If json, it is a list of timestamp and value dicts.
- Raises
- Exception
Wrong number of attribute_id or names_path parameters.
- ValueError
The value of the form or timestamp parameters was wrong.
- TypeError
The parameter value astype was not of type ‘type’.
- get_timesignal(timesignal_id, attribute_id=None, names_path=None, timestamp='datetime', tz=None)
Read asset timesignal attribute values. Exactly one of attribute_id or names_path must be provided.
- Parameters
- timesignal_idstr
Time signal id to read content for.
- attribute_idstr
Id for the attribute to read timesignal content from.
- names_path[str]
List of strings containing the path to the wanted attribute. First name must be the root level asset and last name the wanted attribute name. For example an attribute in the path root_asset/parent_asset/child_asset should be in the form of [‘root_asset’, ‘parent_asset’, ‘child_asset’, ‘attribute_name’].
- timestampstr, default=’datetime’
Optional: In which form to give the timestamps. Must be either ‘datetime’ or ‘epoch’. Default is ‘datetime’.
- tzstr
Optional: Timezone in the form of ±[hh]:[mm], ±[hh][mm], or ±[hh]. Defaults to UTC (‘+00:00’). The data in IoT-TICKET is in UTC, if user wants the data in some other timezone, it can be determined here.
- Returns
- dict
Time signal values.
- write_calculated(data, names_path=None, attribute_ids=None, tz=None)
Write to IoT-TICKET’s Calculated attributes.
Exactly one of attribute_ids or names_path parameters must be given.
- Parameters
- datapandas.DataFrame
Data to write to the attribute. First column must be named ‘timestamp’ and it must contain timestamps in datetime, str or int (epochs). If names_path parameter is used, data columns must be named with corresponding names with the target attribute names.
- names_path[str]
List of strings containing the path to the wanted asset. For example an asset in the path root_asset/parent_asset/child_asset should be in the form of [‘root_asset’, ‘parent_asset’, ‘child_asset’]. Here, dataframe column names are used to find which attributes to write to.
- attribute_ids[str]
The attributes to write data to. The number of attribute_ids given must match the number of data columns in the data.
- tzstr
Optional: Timezone in the form of ±[hh]:[mm], ±[hh][mm], or ±[hh]. Defaults to UTC (‘+00:00’). Note that the timestamps seen in IoT-TICKET are shown as converted to your local timezone.
- Returns
- responsebool
Tells whether sending the requests were succesful. Note that based on this return value being True, it cannot be known whether data was written succesfully, as the operation on server-side is asynchronic.
See also
write_staticFor writing to static String or Number type attributes in IoT-TICKET.
write_telemetryFor writing telemetry data to a device in IoT-TICKET.
- write_static(data, attribute_ids=None, names_path=None, attribute_names=None)
Write to IoT-TICKET’s static String or Number attributes.
There are two ways to locate the wanted target attributes: Use attribute_ids or use names_path leading to an asset and attribute_names for attributes in that asset.
- Parameters
- data[str], [int] or [float]
Data to write to the attribute.
- names_path[str]
List of strings containing the path to the wanted asset. This parameter should be used with the attribute_names parameter. For example an asset in the path root_asset/parent_asset/child_asset should be in the form of [‘root_asset’, ‘parent_asset’, ‘child_asset’].
- attribute_names[str]
List of attribute_names to write data to. Required if names_path is given. The number of attribute_names given must match the number of items in the data.
- attribute_ids[str]
The attributes to write data to. The number of attribute_ids given must match the number of items in the data.
- Returns
- response[bool]
List of booleans telling whether sending the requests were succesful. Note that based on this return value being True, it cannot be known whether data was written succesfully, as the operation on server-side is asynchronic.
- write_telemetry(data, device_id, device_username, device_password, units=None, set_id=None, tz=None)
Write data to a device in IoT-TICKET.
The data can be in form of Telemetry Data or Telemetry Data Set, when writing to a device.
Dataframe column names are used for measurement names.
This method will handle null values differently based on whether writing in the form of a Telemetry Data or a Telemetry Data Set. Having null values and trying to write as a Telemetry Data Set will result in an error. Null values will be dropped if writing as Telemetry Data.
- Parameters
- datapandas.DataFrame or list
Data to write to the device. First column must be named ‘timestamp’ and it must contain timestamps in datetime, str or epochs. There is a limit for data in a single call that is 2048 bytes. Going over that limit will result in a HTTPError with error code 413.
- device_usernamestr
- device_passwordstr
Device credentials. These are created and can be reseted in the IoT-TICKET UI in Data Management -> Devices.
- device_idstr
The device id to write data to.
- units[str]
Optional units of the data as a list of strings. Length of the list must be same as the number of different data items. Max length of a single unit is 20. A single unit can also be an empty string ‘’.
- set_idstr
Optional: If user wants to write data as a Telemetry Data Set, the identifier must be given. By default, data is written as separate Telemetry Data items. If set_id is given, dataframe must not include NaN values.
- tzstr
Optional: Timezone in the form of ±[hh]:[mm], ±[hh][mm], or ±[hh]. Defaults to UTC (‘+00:00’). Note that the timestamps seen in IoT-TICKET are shown as converted to your local timezone.
- Returns
- bool
True if the request was sent succesfully.
- Raises
- Exception
For incorrect parameters or data.
- requests.HTTPError
An error based on requests.response.raise_for_status()
See also
write_staticFor writing to static String or Number type attributes in IoT-TICKET.
write_calculatedFor writing to Calculated type attributes in IoT-TICKET.
- write_timesignal(device_id, device_username, device_password, attribute_name, timestamp, timesignal_id, value, tz=None)
Write a time signal to a device in IoT-TICKET.
- Parameters
- device_idstr
device to add data to.
- device_usernamestr
- device_passwordstr
Device credentials. These are created and can be reseted in the IoT-TICKET UI in Data Management -> Devices.
- attribute_namestr
The attribute identifier name to write the time signal to.
- timestampstr
Timestamps in datetime, str or epochs. If string, must be in ISO8601 format. This form is of ‘{year}-{month}-{day}T{hours}:{minutes}:{seconds}.{milliseconds}Z’.
- timesignal_idstr
Identifier string for time signal. Max 255 characters length.
- valuedict
JSON content that is the actual time signal content.
- tzstr
Optional: Timezone in the form of ±[hh]:[mm], ±[hh][mm], or ±[hh]. Defaults to UTC (‘+00:00’). Note that the timestamps seen in IoT-TICKET are shown as converted to your local timezone.
- Returns
- bool
True if the request was sent succesfully.
- write_timesignals(device_id, device_username, device_password, payload, tz=None)
Write one or multiple time signals to a device in IoT-TICKET based on the complete payload given by the user.
- Parameters
- device_idstr
device to add data to.
- device_usernamestr
- device_passwordstr
Device credentials. These are created and can be reseted in the IoT-TICKET UI in Data Management -> Devices.
- payloaddict
Complete json to send to the server with the key ts containing the list of timesignals. Each timesignal must include the fields “n” for attribute identifier name, “ts” for timestamp, “id” for the timesignal id (max length 255) and “value” for the JSON content that is the actual time signal content. Payload (of two timesignals) can for example be in form of:
{ "ts": [ { "n": "attribute_id", "ts": "2022-10-02T10:10:10.000Z", "id": "timesignal1", "value": { "data": [1, 2, 3] } }, { "n": "attribute_id", "ts": "2022-10-02T11:10:10.000Z", "id": "timesignal2", "value": { "data": [4, 5, 6] } } ] }
Timestamp must be in str or epochs. If string, must be in ISO8601 format. This form is of ‘{year}-{month}-{day}T{hours}:{minutes}:{seconds}.{milliseconds}Z’.
- tzstr
Optional: Timezone in the form of ±[hh]:[mm], ±[hh][mm], or ±[hh]. Defaults to UTC (‘+00:00’). Note that the timestamps seen in IoT-TICKET are shown as converted to your local timezone.
- Returns
- bool
True if the request was sent succesfully.
das.iot_client.interfaces.devices_client module
- class das.iot_client.interfaces.devices_client.DevicesClient
Bases:
objectMethods
get_device(device_id)Get information from a specific device.
get_devices([asset_id, asset_name, names_path])Get device ids.
- get_device(device_id)
Get information from a specific device.
- Parameters
- device_idstr
The device to get information from.
- Returns
- deviceDevice
The Device base class.
- get_devices(asset_id=None, asset_name=None, names_path=None)
Get device ids.
At most one of asset_id or asset_name or names_path must be given. If none of these parameters are given, all devices are returned.
- Parameters
- asset_idstr
Asset id to search devices linked to the given asset only.
- asset_namestr
Asset name to search devices linked to the given asset only.
- names_path[str]
List of strings containing the path to wanted asset to search devices linked to that asset only.
- Returns
- devices[str]
List of device ids.
- Raises
- Exception
If more than one of the parameters asset_id, asset_name and names_path was given.
das.iot_client.interfaces.events_client module
- class das.iot_client.interfaces.events_client.EventsClient
Bases:
object- Attributes
asset_event_active_countGet the number of events that are currently active.
Methods
get_asset_event_history([asset_ids, ...])Get event history from IoT-TICKET for an organization.
get_asset_events_active([asset_ids, ...])Get active asset events from IoT-TICKET for an organization.
write_device_event(device_id, ...[, ...])Write a device event to IoT-TICKET.
write_device_events(device_id, ...[, tz])Write multiple device events to IoT-TICKET based on the complete json payload that is delivered by the user.
- property asset_event_active_count
Get the number of events that are currently active.
- Returns
- int
The number of active events
- Raises
- Exception
If there are over 10000 active events.
- get_asset_event_history(asset_ids=None, asset_names=None, event_type=None, start_time=None, end_time=None, acknowledged=True, only_acknowledged=False, limit=10000)
Get event history from IoT-TICKET for an organization.
Exactly one of asset_ids or asset_names must be provided.
- Parameters
- asset_ids[str]
List of strings to filter from which assets to get events from based on the asset ids.
- asset_names[str]
List of strings to filter from which assets to get events from based on the asset names.
- event_typestr
Optional parameter to filter based on the event’s type. Possible values are: ‘Alarm’, ‘Notification’, ‘Warning’.
- start_timeint or str or datetime
Optional filter parameter to get events that started only after the given start_time. If int, given in epochs. If str, given in ISO8601 format.
- end_timeint or string or datetime
Optional filter parameter to get events that started only before the given end_time. If int, given in epochs. If str, given in ISO8601 format.
- acknowledgedbool, default=True
Optional: whether to include the acknowledged events in the response.
- only_acknowledgedbool, default=False
Optional: whether to include only the acknowledged events in the response.
- limitint, default=10000
Optional parameter to limit the number of events returned. The default value is 10000.
- Returns
- [AssetEventReadResponse]
A list of AssetEventReadResponse objects.
- Raises
- ValueError
If event_type parameter had an invalid value.
- Exception
If both or none of asset_ids and asset_names were given. If only_acknowledged=True and acknowledged=False. This would result in an empty list every time.
- get_asset_events_active(asset_ids=None, asset_names=None, event_type=None, start_time=None, acknowledged=True, limit=10000)
Get active asset events from IoT-TICKET for an organization.
At most one of asset_ids or asset_names must be provided.
- Parameters
- asset_ids[str]
Optional list of strings to filter from which assets to get events from based on the asset ids.
- asset_names[str]
Optional list of strings to filter from which assets to get events from based on the asset names.
- event_typestr
Optional parameter to filter based on the event’s type. Possible values are: ‘Alarm’, ‘Notification’, ‘Warning’.
- start_timeint or str or datetime
Optional filter parameter to get events that started only after the given start_time. If int, given in epochs. If str, given in ISO8601 format.
- acknowledgedbool, default=True
Optional: whether to include acknowledged events in the response.
- limitint, default=10000
Optional parameter to limit the number of events returned. The default value is 10000.
- Returns
- [AssetEventReadResponse]
A list of AssetEventReadResponse objects.
- Raises
- ValueError
If event_type parameter had an invalid value.
- Exception
If both of asset_ids and asset_names were given.
- write_device_event(device_id, device_username, device_password, event_id, message, timestamp, event_group_name=None, event_type=None, severity=None, is_active=None, tz=None)
Write a device event to IoT-TICKET.
- Parameters
- device_idstr
The device to add data to.
- device_usernamestr
- device_passwordstr
Device credentials. These are created and can be reseted in the IoT-TICKET UI in Data Management -> Devices.
- event_idstr
Required text field for event identification. Max length is 255.
- messagestr
Required text field for event message. Max length is 255.
- timestampstr or int or datetime
Timestamp in str or int (epochs) or datetime. If string, must be in ISO8601 format. This form is of ‘{year}-{month}-{day}T{hours}:{minutes}:{seconds}.{milliseconds}Z’.
- event_group_namestr
Optional text fields for event group names. Max length is 255.
- event_typestr
Optional type of the event. Accepted values are “Alarm”, “Warning” and “Notification” (case-sensitive).
- severitystr
Optional severity level for the event. Accepted values are “Low”, “Normal”, “High” and “Critical” (case-sensitive).
- is_activebool
Optional boolean to indicate event state (active / inactive).
- tzstr
Optional: Timezone in the form of ±[hh]:[mm], ±[hh][mm], or ±[hh]. Defaults to UTC (‘+00:00’). Note that the timestamps seen in IoT-TICKET are shown as converted to your local timezone.
- Returns
- bool
True if the request was sent succesfully.
- Raises
- jsonschema.exceptions.ValidationError
For incorrect event parameters.
- requests.HTTPError
An error based on requests.response.raise_for_status().
- write_device_events(device_id, device_username, device_password, payload, tz=None)
Write multiple device events to IoT-TICKET based on the complete json payload that is delivered by the user.
An alternative way to write device events is to use the write_device_event method, which will construct the payload of a single event based on user’s parameters.
- Parameters
- device_idstr
The device to add data to
- device_usernamestr
- device_passwordstr
Device credentials. These are created and can be reseted in the IoT-TICKET UI in Data Management -> Devices.
- payloaddict
Complete json to send with the request. Each event must include the fields “id”, “m” (for message) and “ts” (for timestamp). Optional fields are “gn” (event group name), “type” (“Alarm”, “Warning” or “Notification”), “severity” (“Low”, “Normal”, “High” or “Critical”) and “active” (boolean). Payload (of two events) can for example be in a form of:
{ "e": [{ "id": "111_COLL_ALARM", "m": "Streetlight Collision Alarm", "gn": "Collisions", "ts": "2021-04-17T17:00:00.000Z", "type": "Alarm", "severity": "High", "active": true }, { "id": "112_TOO_HOT", "m": "Temperature currently 94 degrees, (over recommended 50)", "gn": "Temperatures", "ts": "2021-04-17T17:00:00.000Z", "type": "Alarm", "severity": "High", "active": false }, ... ] }
Timestamps must be in str or int (epochs) or datetime. If string, must be in ISO8601 format. This form is of ‘{year}-{month}-{day}T{hours}:{minutes}:{seconds}.{milliseconds}Z’.
- tzstr
Optional: Timezone in the form of ±[hh]:[mm], ±[hh][mm], or ±[hh]. Defaults to UTC (‘+00:00’). Note that the timestamps seen in IoT-TICKET are shown as converted to your local timezone.
- Returns
- bool
True if the request was sent succesfully.
- Raises
- jsonschema.exceptions.ValidationError
For incorrect payload parameter
- requests.HTTPError
An error based on requests.response.raise_for_status()
das.iot_client.interfaces.models_client module
- class das.iot_client.interfaces.models_client.BaseClient
Bases:
object
- class das.iot_client.interfaces.models_client.ModelsClient
Bases:
BaseClient- Attributes
analytics_items_countGet the count of how many analytics items (MLModels, MLServices and OnnxModels) are currently registered to IoT-TICKET.
Methods
delete_model([model_name, model_id])Delete a registered model in IoT-TICKET.
List all data-analytics items that are registered to IoT-TICKET, including models, services and ONNX-models.
get_model_details([model_name, model_id])Get details of a model registered into IoT-TICKET.
List all models that are registered into IoT-TICKET.
register_model(model)Create a registered ML model to IoT-TICKET.
update_model(model)Update a model in IoT-TICKET.
- property analytics_items_count
Get the count of how many analytics items (MLModels, MLServices and OnnxModels) are currently registered to IoT-TICKET.
The amount is limited by IoT-TICKET based on your subscription. The limit can be seen in IoT-TICKET by the organization admin in the Organization management -> Statistics tab.
- Returns
- int
How many analytics items are currently registered to IoT-TICKET.
- delete_model(model_name=None, model_id=None)
Delete a registered model in IoT-TICKET.
Exactly one of model_id or model_name must be given.
A model can only be deleted if it is not used in an asset in IoT-TICKET
- Parameters
- model_namestr
The name of the model in IoT-TICKET.
- model_idstr
The id of the model in IoT-TICKET. Note that the model id is not visible in the IoT-TICKET UI, but must be queried with the .get_model_list()-method
- Returns
- bool
True if the model was deleted.
- Raises
- Exception
If the model was in use in an asset in IoT-TICKET
- get_all_analytics_items()
List all data-analytics items that are registered to IoT-TICKET, including models, services and ONNX-models.
- Returns
- [dict]
List of dicts containing the model id, name, level and type. Type is one of ‘MLModel’, ‘MLService’ or ‘OnnxModel’. Level is one of ‘organization’, ‘subscription’ or ‘platform’.
- get_model_details(model_name=None, model_id=None)
Get details of a model registered into IoT-TICKET.
Exactly one of model_id or model_name must be given.
- Parameters
- model_namestr
The name of the model in IoT-TICKET.
- model_idstr
The id of the model in IoT-TICKET. Note that the model id is not visible in the IoT-TICKET UI, but must be queried with the .get_model_list()-method.
- Returns
- dict
The details of the model including the following keys: id, name, description, helpText, triggerUrl, jobId, clientId, token, organization, subscription, updatedBy, createdBy, updatedAt, createdAt, inputs, outputs, headers.
- Raises
- Exception
If either both or none of model_id and model_name were given.
- get_model_list()
List all models that are registered into IoT-TICKET.
- Returns
- [dict]
Registered models as a list of dicts including the following keys: id, name, jobId, organization, subscription.
- register_model(model)
Create a registered ML model to IoT-TICKET.
- Parameters
- modeldict
The dict must include following keys: name, description, help_text, trigger_url, method (one of ‘POST’, ‘GET’, ‘PUT’), client_id&scope (or headers), inputs and outputs. Best practice is to give this with the DatabricksJob.as_dict() method (see example).
- Returns
- str
The id of the registered model as a string.
- Raises
- ValidationError
If given model dict was in a wrong form.
Examples
Best practice is to use helper classes to create a job instance:
>>> from das import DatabricksJob >>> job = DatabricksJob(name = ...)
DatabricksClient from the das package can also be used to do
>>> job_json = databricksClient.jobs.list_jobs()['jobs'][job index] >>> job = DatabricksJob.from_json(job_json, credential)
The inputs and outputs must be defined for the job instance:
>>> job.notebook_inputs = [NotebookNode('name', ...)] >>> job.notebook_outputs = [NotebookNode('name', ...)]
The model can then be registered:
>>> client.register_model(model=job.as_dict())
- update_model(model)
Update a model in IoT-TICKET.
If the model is being used in an asset, only basic info can be updated. This means that the inputs or outputs cannot be updated while being used.
- Parameters
- modeldict
The dict must include the keys for basic info, which are name, description, help_text, trigger_url, method, job_id and credential_id. The dict can include also the keys inputs and outputs, but in this case the model cannot be in used in an asset or the call will fail. Best practice is to give this parameter with the DatabricksJob.as_dict() method for full info or DatabricksJob.base_body property for the basic info.
- Returns
- bool
True if model was updated.
- Raises
- ValidationError
If the given model dict was in a wrong form.
- Exception
If the “model” parameter included more than the basic info, but the registered model was in use in an asset in IoT-TICKET.
- class das.iot_client.interfaces.models_client.OnnxClient
Bases:
objectMethods
delete_onnx_model([model_name, model_id])Delete an ONNX model that is registered into IoT-TICKET
get_onnx_model_details([model_name, model_id])Get details of a registered ONNX Model.
Get all registered ONNX Models.
register_onnx_model(name[, onnx_model, ...])Register a model to IoT-TICKET in ONNX (Open Neural Network Exchange) form.
update_onnx_model(payload[, model_id])Update ONNX model basic information.
- delete_onnx_model(model_name=None, model_id=None)
Delete an ONNX model that is registered into IoT-TICKET
One of model_id or model_name must be given.
- Parameters
- model_name: str
The name of the model to delete.
- model_idstr
The id of the model to delete. Note that the model id is not visible in the IoT-TICKET UI, but must be queried with the .get_onnx_model_list()-method.
- Returns
- bool
True if model was deleted succesfully.
- Raises
- Exception
If either both or none of model_id and model_name were given.
- get_onnx_model_details(model_name=None, model_id=None)
Get details of a registered ONNX Model.
Exactly one of model_id or model_name must be given.
- Parameters
- model_namestr
The name of the model to get.
- model_idstr
The id of the model to get. Note that the model id is not visible in the IoT-TICKET UI, but must be queried with the .get_onnx_model_list()-method.
- Returns
- dict
The model as a dict containing the keys id, name, description, helpText, inputs, outputs, organization, subscription, updatedBy, createdBy, updatedAt, createdAt.
- Raises
- Exception
If either both or none of model_id and model_name were given.
- get_onnx_model_list()
Get all registered ONNX Models.
- Returns
- [dict]
List of dicts containing the model id, name, level and type. For this call, type is always ‘OnnxModel’. Level is one of ‘organization’, ‘subscription’ or ‘platform’.
- register_onnx_model(name, onnx_model=None, file_location=None, description=None, help_text=None)
Register a model to IoT-TICKET in ONNX (Open Neural Network Exchange) form. One of the onnx_file or file_location must be given.
- Parameters
- namestr
Name of the model.
- onnx_modelonnx.ModelProto,
The ONNX model.
- file_locationstr
Path to the ONNX file.
- descriptionstr
Model description to be shown in IoT-TICKET. Can be empty or missing.
- help_textstr
Model help text in markdown. Can be empty or missing.
- Returns
- str
The id of the created ONNX Model.
- Raises
- Exception
Multiple or none of the parameters onnx_model and file_location were provided. The given file_location path didn’t lead to a file with type .onnx
- TypeError
The given onnx model was not a ModelProto object.
- FileNotFoundError
File with the given file_location path was not found.
- update_onnx_model(payload, model_id=None)
Update ONNX model basic information.
- Parameters
- payloaddict
The model information to update. Must contain at least the key ‘name’. Can also contain the keys ‘description’ and ‘help_text’ to update those. These will be converted to strings.
- model_idstr
The id of the model to update. Optional, if the name included in the payload is unique. Note that the model id is not visible in the IoT-TICKET UI, but must be queried with the .get_onnx_model_list()-method.
- Returns
- bool
True if model was edited succesfully.
- Raises
- Exception
If the given payload parameter was invalid.
- class das.iot_client.interfaces.models_client.ServicesClient
Bases:
BaseClientMethods
delete_service([service_name, service_id])Delete a registered service in IoT-TICKET.
get_service_details([service_name, service_id])Get details of a service registered into IoT-TICKET.
List all services that are registered into IoT-TICKET.
register_service(service)Create a registered ML service to IoT-TICKET.
update_service(service[, service_name, ...])Update a service in IoT-TICKET.
- delete_service(service_name=None, service_id=None)
Delete a registered service in IoT-TICKET.
Exactly one of service_id or service_name must be given.
- Parameters
- service_namestr
The name of the service in IoT-TICKET.
- service_idstr
The id of the service in IoT-TICKET. Note that the service id is not visible in the IoT-TICKET UI, but must be queried with the .get_service_list()-method.
- Returns
- bool
True if the service was deleted
- Exception
If either both or none of service_id and service_name were given.
- get_service_details(service_name=None, service_id=None)
Get details of a service registered into IoT-TICKET.
Exactly one of service_id or service_name must be given.
- Parameters
- service_namestr
The name of the service in IoT-TICKET.
- service_idstr
The id of the service in IoT-TICKET. Note that the service id is not visible in the IoT-TICKET UI, but must be queried with the .get_service_list()-method.
- Returns
- dict
The details of the service including the following keys: id, name, description, helpText, triggerUrl, requestContainsTimestamps, responseContainsTimestamps, headers, inputSchema, outputSchema, organization, subscription, updatedBy, createdBy, updatedAt, createdAt.
- Raises
- Exception
If either both or none of service_id and service_name were given.
- get_service_list()
List all services that are registered into IoT-TICKET.
- Returns
- [dict]
Registered services as a list of dicts including the following keys: id, name, description, helpText, triggerUrl, requestContainsTimestamps, responseContainsTimestamps, headers, inputSchema, outputSchema, organization, subscription, updatedBy, createdBy, updatedAt, createdAt. Values of only basic info are in the returned value, as others have None values.
- register_service(service)
Create a registered ML service to IoT-TICKET.
- Parameters
- servicedict
The dict must include following keys: name, description, help_text, trigger_url, method, client_id&scope (or headers), input_schema, request_contains_timestamps, output_schema and response_contains_timestamps. Best practice is to give this with one of the registration classes’ .as_dict() method (see example).
- Returns
- str
The id of the registered service as a string.
- Raises
- ValidationError
If given service dict was in a wrong form.
Examples
Best practice is to use helper registration classes to create a function instance:
>>> from das import AzureFunction >>> job = AzureFunction(name = ...)
AzureFunctionsClient from the das package can also be used to do
>>> function_json = azureFunctionsClient.list_functions()['value'][function index] >>> function = AzureFunction.from_json(function_json, credential)
The inputs and outputs must be defined, or they can be inferred by running the function:
>>> function.try_out_infer(example_data, inplace=True)
Tell IoT-TICKET wheter to send timestamps when running the function:
>>> function['request_contains_timestamps'] = False >>> function['response_contains_timestamps'] = False
The service can then be registered:
>>> client.register_service(service=function.as_dict())
- update_service(service, service_name=None, service_id=None)
Update a service in IoT-TICKET.
Exactly one of service_id or service_name must be given.
- Parameters
- servicedict
The dict must include the keys for at least the basic info, which are name, description, help_text, trigger_url, method, credential_id, request_contains_timestamps and response_contains_timestamps. The dict can also include keys input_schema and output_schema to update those. Best practice is to give this with on of the .as_dict() method of the registration class for full info or .base_body property for basic info.
- service_namestr
The name of the service in IoT-TICKET.
- service_idstr
The id of the service in IoT-TICKET. Note that the service id is not visible in the IoT-TICKET UI, but must be queried with the .get_service_list()-method.
- Returns
- bool
True if service was updated.
- Raises
- ValidationError
If given service dict was in a wrong form.
- Exception
If either both or none of service_id and service_name were given.
das.iot_client.interfaces.organizations_client module
- class das.iot_client.interfaces.organizations_client.OrganizationsClient
Bases:
objectMethods
get_organization_details([organization_id])Get details for current organization (default), or for the organization of which id was given.
Read organizations information.
- get_organization_details(organization_id=None)
Get details for current organization (default), or for the organization of which id was given.
Note that this method is only available for subscription owner.
- Parameters
- organization_idstr
Optional organization_id to find details for another organization.
- Returns
- dict
Organization’s details as a dict including the following keys: id, name, description, enable, contactPerson, ccountManager, limits, usedLimits, createdBy, modifiedBy, created, lastModified
- get_organizations()
Read organizations information.
- Returns
- [Organization]
All organizations for this user as a list of Organization objects.