2 Replies Latest reply on Sep 24, 2018 9:00 PM by Ckoshnick

    Python PI Web API library - search points by tag name, pull data with results

    Ckoshnick

      Hello! I have a question regarding the use of the Python library for the PI web API (Announcing PI Web API client library for Python )

       

      Our office has used our own Python library to access the PI web API with just a few functions. Our main strategy was to use a tag name query to return the webIDs then use the webIDs to get data. The search URL followed the following syntax: root / dataserver / <dataserver> / points?nameFilter= <point query> where <point query> would be a search string for PI Point tag names that supports wild-carding with *. Generally, we would return the webID and tagName with the using the following params = {"selectedFields": "Items.WebId;Items.Name"} in the web request. Our data getting method used the following structure root / streams /  <Web_ID> /  <calculation> which would return a json that we parsed into a pd.DataFrame.

       

      My question is how to use the osisoft.pidevclub.piwebapi.pi_web_api_client to do a similar thing. Most of the documentation shows data get requests using the webID or Path conventions, but I can't find a function to let me search for WebIDs. Is there a method for obtaining webIDs by searching tag names as I explained above?

       

      >>client.system.versions()

      {'OSIsoft.REST': {'build': '478',

        'full_version': '1.9.0.478',

        'major_minor_revision': '1.9.0',

        'web_exception': None}, 'OSIsoft.REST.Documentation': {'build': '478',

        'full_version': '1.9.0.478',

        'major_minor_revision': '1.9.0',

        'web_exception': None}, 'OSIsoft.Search.SvcLib': {'build': '2561',

        'full_version': '1.6.0.2561',

        'major_minor_revision': '1.6.0',

        'web_exception': None}}

       

      Thanks!

        • Re: Python PI Web API library - search points by tag name, pull data with results
          tramachandran

          The PI Web API Client libraries are primarily based on the Open API specifications in PI Web API.

          In order for you to get to any controller (e.g. here you are using DataServer) you can invoke the corresponding methods in the pi_web_api client that you generate.

          The pi_web_api_client.py maps the APIs in the PI-Web-API-Client-Python/osisoft/pidevclub/piwebapi/api/ directory. You will find statements like below in that script

          "from osisoft.pidevclub.piwebapi.api.data_server_api import DataServerApi"

          The data_server_api.py should contain all the functions that are available in the PI Web API specification.

          Here the method is def get_points(....) should correspond to GET dataservers/{webId}/points

          The above steps should also be helpful to get to any other controller in the spec easily from the client libs.

           

          TLDR;

          from osisoft.pidevclub.piwebapi.pi_web_api_client import PIWebApiClient 
          client = PIWebApiClient("https://test.osisoft.com/piwebapi", False, "username", "password", True) 
          # pass appropriate arguments
          pts = client.dataServer.get_points(web_id, max_count=None, name_filter=None, selected_fields=None, start_index=None, web_id_type=None, **kwargs)
          
          1 of 1 people found this helpful