OSI PI API Class

OSI PI Web API class allows the user to communicate with OSI PI web API using python

Prerequisites:

  • Python > 3.7

  • OSI PI access

class OSIPI_WebAPI.OSIPI_WebAPI(piwebapi_url, username, password, authentication_type='basic', max_attempts=1, timeout=None, verbose=False, verify=True)
Parameters
  • piwebapi_url – (string) - OSI PI base URL.

  • username – (string) - OSI PI username.

  • password – (string) - OSI PI password.

  • authentication_type – (string - optional) - This can be either ntlm or basic (default value basic).

  • max_attempts – (int - optional) - Maximum number of attempts if disconnected (default value 1).

  • timeout – (int - optional) - Timeout threshold in seconds (default value None).

  • verbose – (bool - optional) - Print internal messages if True (default value False).

  • verify – (bool - optional) - By pass SSL verification if True (default value True).

Returns

None

authenticate(authentication_type, username, password, verbose=False)

Authenticate and create API call security method

Parameters
  • authentication_type – (string) - Authentication method to use: basic or ntlm.

  • username – (string) - The user’s credentials name.

  • password – (string) - The user’s credentials password.

  • verbose – (bool - optional) - Print internal messages if True (default value False).

Returns

(HttpNtlmAuth or HTTpBasicAuth)

getPointAttributes(webID, pageSize=None, verbose=False)

Get point (sensor) system attributes

For more details see https://techsupport.osisoft.com/Documentation/PI-Web-API/help/controllers/point/actions/getattributes.html

Parameters
  • webID – (string) - Point (sensor) web ID.

  • pageSize – (int - optional) - Page size for response (default value None). When default is used the default OSI PI page size will be used (1000).

  • verbose – (bool - optional) - Print internal messages if True (default value False).

Returns

(tuple - dict or string, string) - response (json or error string) and response status code.

getPointsList(dataServerName=None, pageSize=None, verbose=False)

Get full point list (sensors) in a specified data server. If data server is None, then all points from all data servers will be returned

Parameters
  • dataServerName – (string - optional) - Specific data server to retrieve data from (default value None).

  • pageSize – (int - optional) - Page size for response (default value None). When default is used the default OSI PI page size will be used (1000).

  • verbose – (bool - optional) - Print internal messages if True (default value False).

Returns

(tuple - dict, None) - List of all points (sensors). The second argument of the tuple is always None

([{'ServerName': 'xxx', 'Points': 'xxx', 'ResponseStatus': 'xxx'}], None)

getStreamData(webID, searchType='end', parameters=None, pageSize=None, verbose=False)

Get stream data for a specified point (sensor) using point’s webID. Search filter can be applied to narrow down the result

Parameters
  • webID – (string) - Point (sensor) web ID.

  • searchType

    (string - optional) - Search type to be used, can be one of the following values (default value end).

    ['end', 'interpolated', 'recorded', 'plot', 'summary', 'value']
    

  • parameters – (string - optional) - Additional parameters to filter the query (default value None). See https://techsupport.osisoft.com/Documentation/PI-Web-API/help/controllers/stream.html for additional information for each search type.

  • pageSize – (int - optional) - Page size for response (default value None). When default is used the default OSI PI page size will be used (1000).

  • verbose – (bool - optional) - Print internal messages if True (default value False).

Returns

(tuple - dict or string, string) - response (json or error string) and response status code.

getStreamDataSummary(webID, startTime=None, endTime=None, summaryType=None, pageSize=None, verbose=False)

Get stream data summary for a specified point (sensor) using point’s webID. Search filter can be applied to narrow down the result.

For more details see https://techsupport.osisoft.com/Documentation/PI-Web-API/help/controllers/stream/actions/getsummary.html

Parameters
  • webID – (string) - Point (sensor) web ID.

  • startTime – (string - optional) -Start time filter (default vale None)

  • endTime – (string - optional) -End time filter (default vale None)

  • summaryType

    (string - optional) - Summary type requested, can be one of the following values (default value None).

    ['Total', 'Average', 'Minimum', 'Maximum', 'Range',
    'StdDev', 'PopulationStdDev', 'Count', 'PercentGood',
    'TotalWithUOM', 'All', 'AllForNonNumeric']
    

  • pageSize – (int - optional) - Page size for response (default value None). When default is used the default OSI PI page size will be used (1000).

  • verbose – (bool - optional) - Print internal messages if True (default value False).

Returns

(tuple - dict or string, string) - response (json or error string) and response status code.

Get OSI PI DataServers and AssetServers available databases

Parameters
  • pageSize – (int - optional) - Page size for response (default value None). When default is used the default OSI PI page size will be used (1000).

  • verbose – (bool - optional) - Print internal messages if True (default value False).

Returns

(dict) - System links dictionary

{'<serverType>': [{'Name': 'xxx', 'Link': 'xxx', 'WebID': 'xxx'}]}

<serverType> is either DataServers or AssetServers

validate_and_return_response(response, message='', raw=False)

Validate response by comparing it against the acceptable status codes. Returns response and status code.

Parameters
  • response – (requests.response) - The response from the query.

  • message – (string - optional) - Desired custom error message.

  • raw – (bool - optional) - Defines whether to return response raw format or json (default value False).

Returns

(tuple - dict or string, string) - response (json, raw or error string) and response status code.

webapi_get_request(url, pageSize=None, message='', raw=False)

Execute get request and validate response.

Parameters
  • url – (string) - URL to be executed in the get request.

  • pageSize – (int - optional) - Page size for response (default value None). When default is used the default OSI PI page size will be used (1000).

  • message – (string - optional) - Desired custom error message.

  • raw – (bool - optional) - Defines whether to return response raw format or json (default value False).

Returns

(tuple - dict or string, string) - response (json, raw or error string) and response status code.