Skip to main content

A library for getting data from PIServers

Project description

pyPIAF

Python bindings for the PI AF SDK

This library provides access to the PI AF SDK using the pythonnet library. It also provides simple helper method for common conversions of C# objets to python objects.

Example: Get current value of PIPoint

import pyPIAF.server.connect
import pyPIAF
from OSIsoft.AF.Asset import AFValue
from OSIsoft.AF.PI import PIPoint
from OSIsoft.AF.PI import PIServer

server: PIServer
with pyPIAF.server.connect.connect_server_ctx("SERVER_NAME") as server:
    point: PIPoint = PIPoint.FindPIPoint(server, "POINT_NAME")

    current_value: AFValue = point.current_value()

Example: Get the actual values in a date range as a pandas DataFrame

import pyPIAF.server.connect
from datetime import datetime

import pandas as pd
import pyPIAF
from OSIsoft.AF.Asset import AFValues
from OSIsoft.AF.Data import AFBoundaryType
from OSIsoft.AF.PI import PIPoint
from OSIsoft.AF.PI import PIServer
from OSIsoft.AF.Time import AFTime
from OSIsoft.AF.Time import AFTimeRange

server: PIServer
with pyPIAF.server.connect.connect_server_ctx("SERVER_NAME") as server:
    point: PIPoint = PIPoint.FindPIPoint(server, "POINT_NAME")

    end: datetime = datetime.now()
    start: datetime = datetime(year=end.year, month=1, day=1)

    start_time: AFTime = pyPIAF.to_af_time(start)
    end_time: AFTime = pyPIAF.to_af_time(end)

    time_range: AFTimeRange = AFTimeRange(start_time, end_time)
    boundary_type: AFBoundaryType = AFBoundaryType.Inside
    filter_expression: str = ""
    include_filtered_values: bool = False

    values: AFValues = point.RecordedValues(
        time_range,
        boundary_type,
        filter_expression,
        include_filtered_values,
    )

    data: pd.DataFrame = pyPIAF.to_dataframe(values)

Example: Get interpolated values in a date range as a pandas DataFrame

import pyPIAF.server.connect
from datetime import datetime
from datetime import timedelta

import pandas as pd
import pyPIAF
from OSIsoft.AF.Asset import AFValues
from OSIsoft.AF.PI import PIPoint
from OSIsoft.AF.PI import PIServer
from OSIsoft.AF.Time import AFTime
from OSIsoft.AF.Time import AFTimeRange
from OSIsoft.AF.Time import AFTimeSpan

server: PIServer
with pyPIAF.server.connect.connect_server_ctx("SERVER_NAME") as server:
    point: PIPoint = PIPoint.FindPIPoint(server, "POINT_NAME")

    end = datetime.now()
    start = datetime(year=end.year, month=1, day=1)
    span = timedelta(hours=1)

    start_time: AFTime = pyPIAF.to_af_time(start)
    end_time: AFTime = pyPIAF.to_af_time(end)
    time_span: AFTimeSpan = pyPIAF.to_af_time_span(span)

    time_range: AFTimeRange = AFTimeRange(start_time, end_time)
    interval: AFTimeSpan = pyPIAF.to_af_time_span(span)
    filter_expression: str = ""
    include_filtered_values: bool = False

    values: AFValues = point.InterpolatedValues(
        time_range,
        interval,
        filter_expression,
        include_filtered_values,
    )

    data: pd.DataFrame = pyPIAF.to_dataframe(values)

TODO

  • More utility functions

Contributing

Currently, the code and the issues are hosted on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pypiaf-4.1.2.tar.gz (10.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pypiaf-4.1.2-py3-none-any.whl (10.8 MB view details)

Uploaded Python 3

File details

Details for the file pypiaf-4.1.2.tar.gz.

File metadata

  • Download URL: pypiaf-4.1.2.tar.gz
  • Upload date:
  • Size: 10.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pypiaf-4.1.2.tar.gz
Algorithm Hash digest
SHA256 2a34a60daf158ab97b9bbbe4a78c3dd8da62397dff0d0668c8b3ced68a6ed6f2
MD5 1a0a22abd2980467d96c8542a2a732eb
BLAKE2b-256 62deec9095d6477c318f58987c293c8dc48458cd81bedbf0475b3a60853fa96e

See more details on using hashes here.

File details

Details for the file pypiaf-4.1.2-py3-none-any.whl.

File metadata

  • Download URL: pypiaf-4.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for pypiaf-4.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b830d89dcfac59423873a45217324c122fba9d757441d7e299263b5cba210d97
MD5 373ccec2e026304545a465e61ec1f132
BLAKE2b-256 952c24dc8c92135beacb7a8b530f1bc3efc8b522c09c8069a753d2f8b2fc4d6c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page