PIconnect.PI module#
- class PIconnect.PI.PIServer(server: str | None = None, username: str | None = None, password: str | None = None, domain: str | None = None, authentication_mode: AuthenticationMode = AuthenticationMode.PI_USER_AUTHENTICATION, timeout: int | None = None)#
PIServer is a connection to an OSIsoft PI Server.
- Parameters:
server (str, optional) – Name of the server to connect to, defaults to None
username (str, optional) – Username to connect to the server, defaults to None
password (str, optional) – Password for the username, defaults to None
domain (str, optional) – Domain of the username, defaults to None
authentication_mode (AuthenticationMode, optional) – Authentication mode to use, defaults to PI_USER_AUTHENTICATION
timeout (int, optional) – the maximum seconds an operation can take
Note
If the specified server is unknown a warning is thrown and the connection is redirected to the default server, as if no server was passed. The list of known servers is available in the PIServer.servers dictionary.
- search(query: str | list[str], source: str | None = None) DataContainerCollection[PIPoint]#
Search PIPoints on the PIServer.
- Parameters:
- Returns:
A collection of
PIPointobjects as a result of the query.- Return type:
Todo
Reject searches while not connected
- property server_name#
Name of the connected server.
- class PIconnect.PI.PIPoint(pi_point: PIPoint)#
Bases:
DataContainerReference to a PI Point to get data and corresponding metadata from the server.
- Parameters:
pi_point (AF.PI.PIPoint) – Reference to a PIPoint as returned by the SDK
- filtered_summaries(start_time: str | datetime, end_time: str | datetime, interval: str | timedelta | Timedelta, filter_expression: str, summary_types: SummaryType, calculation_basis: CalculationBasis = CalculationBasis.TIME_WEIGHTED, filter_evaluation: ExpressionSampleType = ExpressionSampleType.EXPRESSION_RECORDED_VALUES, filter_interval: str | timedelta | Timedelta | None = None, time_type: TimestampCalculation = TimestampCalculation.AUTO) DataFrame#
Return one or more summary values for each interval within a time range.
- Parameters:
start_time (str or datetime) – String containing the date, and possibly time, from which to retrieve the values. This is parsed, together with end_time, using
Time.to_af_time_range().end_time (str or datetime) – String containing the date, and possibly time, until which to retrieve values. This is parsed, together with start_time, using
Time.to_af_time_range().interval (str, datetime.timedelta or pandas.Timedelta) – String containing the interval at which to extract data. This is parsed using
Time.to_af_time_span().filter_expression (str, optional) – Defaults to ‘’. Query on which data to include in the results. See Filtering values for more information on filter queries.
summary_types (int or Data.SummaryType) – Type(s) of summaries of the data within the requested time range.
calculation_basis (int or Data.CalculationBasis, optional) – Event weighting within an interval. See Event weighting and
CalculationBasisfor more information. Defaults toCalculationBasis.TIME_WEIGHTED.filter_evaluation (int or Data.ExpressionSampleType, optional) – Determines whether the filter is applied to the raw events in the database, of if it is applied to an interpolated series with a regular interval. Defaults to
ExpressionSampleType.EXPRESSION_RECORDED_VALUES.filter_interval (str, optional) – String containing the interval at which to extract apply the filter. This is parsed using
Time.to_af_time_span().time_type (int or Data.TimestampCalculation, optional) – Timestamp to return for each of the requested summaries. See Summary timestamps and
TimestampCalculationfor more information. Defaults toTimestampCalculation.AUTO.
- Returns:
Dataframe with the unique timestamps as row index and the summary name as column name.
- Return type:
- interpolated_value(time: str | datetime) Series#
Return a pd.Series with an interpolated value at the given time.
- Parameters:
time (str, datetime) – String containing the date, and possibly time, for which to retrieve the value. This is parsed, using
Time.to_af_time().- Returns:
A pd.Series with a single row, with the corresponding time as the index
- Return type:
- interpolated_values(start_time: str | datetime, end_time: str | datetime, interval: str | timedelta | Timedelta, filter_expression: str = '') Series#
Return a pd.Series of interpolated data.
Data is returned between start_time and end_time at a fixed interval. The first two allow for time specification relative to “now” by use of the asterisk.
filter_expression is an optional string to filter the returned values, see the Performance equation documentation for more information.
The AF SDK allows for inclusion of filtered data, with filtered values marked as such. At this point PIconnect does not support this and filtered values are always left out entirely.
- Parameters:
start_time (str or datetime.datetime) – Containing the date, and possibly time, from which to retrieve the values. This is parsed, together with end_time, using
Time.to_af_time_range().end_time (str or datetime.datetime) – Containing the date, and possibly time, until which to retrieve values. This is parsed, together with start_time, using
Time.to_af_time_range().interval (str, datetime.timedelta or pandas.Timedelta) – String containing the interval at which to extract data. This is parsed using
Time.to_af_time_span().filter_expression (str, optional) – Defaults to ‘’. Query on which data to include in the results. See Filtering values for more information on filter queries.
- Returns:
Timeseries of the values returned by the SDK
- Return type:
- recorded_value(time: str | datetime, retrieval_mode: RetrievalMode = RetrievalMode.AUTO) Series#
Return a pd.Series with the recorded value at or close to the given time.
- Parameters:
time (str) – String containing the date, and possibly time, for which to retrieve the value. This is parsed, using
Time.to_af_time().retrieval_mode (int or RetrievalMode) – Flag determining which value to return if no value available at the exact requested time.
- Returns:
A pd.Series with a single row, with the corresponding time as the index.
- Return type:
- recorded_values(start_time: str | datetime, end_time: str | datetime, boundary_type: BoundaryType = BoundaryType.INSIDE, filter_expression: str = '')#
Return a pd.Series of recorded data.
Data is returned between the given start_time and end_time, inclusion of the boundaries is determined by the boundary_type attribute. Both start_time and end_time are parsed by AF.Time and allow for time specification relative to “now” by use of the asterisk.
By default the boundary_type is set to ‘inside’, which returns from the first value after start_time to the last value before end_time. The other options are ‘outside’, which returns from the last value before start_time to the first value before end_time, and ‘interpolate’, which interpolates the first value to the given start_time and the last value to the given end_time.
filter_expression is an optional string to filter the returned values, see OSIsoft PI documentation for more information.
The AF SDK allows for inclusion of filtered data, with filtered values marked as such. At this point PIconnect does not support this and filtered values are always left out entirely.
- Parameters:
start_time (str or datetime) – Containing the date, and possibly time, from which to retrieve the values. This is parsed, together with end_time, using
Time.to_af_time_range().end_time (str or datetime) – Containing the date, and possibly time, until which to retrieve values. This is parsed, together with start_time, using
Time.to_af_time_range().boundary_type (BoundaryType) – Specification for how to handle values near the specified start and end time. Defaults to
BoundaryType.INSIDE.filter_expression (str, optional) – Defaults to ‘’. Query on which data to include in the results. See Filtering values for more information on filter queries.
- Returns:
Timeseries of the values returned by the SDK
- Return type:
- summaries(start_time: str | datetime, end_time: str | datetime, interval: str | timedelta | Timedelta, summary_types: SummaryType, calculation_basis: CalculationBasis = CalculationBasis.TIME_WEIGHTED, time_type: TimestampCalculation = TimestampCalculation.AUTO) DataFrame#
Return one or more summary values for each interval within a time range.
- Parameters:
start_time (str or datetime) – Containing the date, and possibly time, from which to retrieve the values. This is parsed, together with end_time, using
Time.to_af_time_range().end_time (str or datetime) – Containing the date, and possibly time, until which to retrieve values. This is parsed, together with start_time, using
Time.to_af_time_range().interval (str, datetime.timedelta or pandas.Timedelta) – String containing the interval at which to extract data. This is parsed using
Time.to_af_time_span().summary_types (int or SummaryType) – Type(s) of summaries of the data within the requested time range.
calculation_basis (int or CalculationBasis, optional) – Event weighting within an interval. See Event weighting and
CalculationBasisfor more information. Defaults toCalculationBasis.TIME_WEIGHTED.time_type (int or TimestampCalculation, optional) – Timestamp to return for each of the requested summaries. See Summary timestamps and
TimestampCalculationfor more information. Defaults toTimestampCalculation.AUTO.
- Returns:
Dataframe with the unique timestamps as row index and the summary name as column name.
- Return type:
- summary(start_time: str | datetime, end_time: str | datetime, summary_types: SummaryType, calculation_basis: CalculationBasis = CalculationBasis.TIME_WEIGHTED, time_type: TimestampCalculation = TimestampCalculation.AUTO) DataFrame#
Return one or more summary values over a single time range.
- Parameters:
start_time (str or datetime) – Containing the date, and possibly time, from which to retrieve the values. This is parsed, together with end_time, using
Time.to_af_time_range().end_time (str or datetime) – Containing the date, and possibly time, until which to retrieve values. This is parsed, together with start_time, using
Time.to_af_time_range().summary_types (int or SummaryType) – Type(s) of summaries of the data within the requested time range.
calculation_basis (int or CalculationBasis, optional) – Event weighting within an interval. See Event weighting and
CalculationBasisfor more information. Defaults toCalculationBasis.TIME_WEIGHTED.time_type (int or TimestampCalculation, optional) – Timestamp to return for each of the requested summaries. See Summary timestamps and
TimestampCalculationfor more information. Defaults toTimestampCalculation.AUTO.
- Returns:
Dataframe with the unique timestamps as row index and the summary name as column name.
- Return type:
- update_value(value: Any, time: str | datetime | None = None, update_mode: UpdateMode = UpdateMode.NO_REPLACE, buffer_mode: BufferMode = BufferMode.BUFFER_IF_POSSIBLE) None#
Update value for existing PI object.
- Parameters:
value – value type should be in cohesion with PI object or it will raise PIException: [-10702] STATE Not Found.
time (datetime, optional) – It is not possible to set future value, it raises PIException: [-11046] Target Date in Future.
value. (You can combine update_mode and time to change already stored)
- property created#
Return the creation datetime of a point.
- property description#
Return the description of the PI Point.
Todo
Add setter to alter displayed description
- property last_update#
Return the time at which the last value for this PI Point was recorded.
- property stepped_data: bool#
Return False when the PIPoint contains continuous data or True when stepped data.
- property units_of_measurement: str | None#
Return the units of measument in which values for this PI Point are reported.
- version = '0.3.0'#