Metadata-Version: 2.4
Name: pyPIAF
Version: 4.0.0
Summary: A library for getting data from PIServers
Author-email: "Ryan Smith (s316353)" <rjsmith3@aep.com>
Maintainer-email: TSAM <TSAM@aep.com>
Project-URL: Homepage, https://github.aepsc.com/s316353/pyPIAF
Project-URL: Download, https://github.aepsc.com/s316353/pyPIAF/releases
Project-URL: Source, https://github.aepsc.com/s316353/pyPIAF
Project-URL: Documentation, https://github.aepsc.com/s316353/pyPIAF/wiki
Project-URL: Issue Tracker, https://github.aepsc.com/s316353/pyPIAF/issues
Keywords: PI,PIAF,OSIsoft,Plant Information,Asset Framework
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Framework :: Flake8
Classifier: Framework :: Pytest
Classifier: Framework :: tox
Classifier: License :: Other/Proprietary License
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Typing :: Typed
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: pythonnet>=3.0.5
Requires-Dist: python-dateutil>=2.9.0
Requires-Dist: pandas>=2.2.3
Provides-Extra: dev
Requires-Dist: pytest>=8.3.4; extra == "dev"
Requires-Dist: tox>=4.23; extra == "dev"

[//]: # ([![PyPI]&#40;https://img.shields.io/pypi/v/tox?style=flat-square&#41;]&#40;https://pypi.org/project/tox/&#41;)

[//]: # ([![Supported Python versions]&#40;https://img.shields.io/pypi/pyversions/tox.svg&#41;]&#40;https://pypi.org/project/tox/&#41;)

[//]: # ([![check]&#40;https://github.com/tox-dev/tox/actions/workflows/check.yml/badge.svg&#41;]&#40;https://github.com/tox-dev/tox/actions/workflows/check.yml&#41;)

[//]: # ([![Documentation status]&#40;https://readthedocs.org/projects/tox/badge/?version=latest&style=flat-square&#41;]&#40;https://tox.readthedocs.io/en/latest/?badge=latest&#41;)

[//]: # ([![Code style:black]&#40;https://img.shields.io/badge/code%20style-black-000000.svg&#41;]&#40;https://github.com/psf/black&#41;)

[//]: # ([![Downloads]&#40;https://pepy.tech/badge/tox/month&#41;]&#40;https://pepy.tech/project/tox/month&#41;)

[//]: # (<a href="https://tox.readthedocs.io"><img src="https://raw.githubusercontent.com/tox-dev/tox/master/docs/_static/img/tox.png" alt="tox logo" height="150px" align="right"></a>)

# 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.

[//]: # (tox is highly [configurable]&#40;https://tox.readthedocs.io/en/latest/config.html&#41; and)

[//]: # ([pluggable]&#40;https://tox.readthedocs.io/en/latest/plugins.html&#41;.)

## Example: Get current value of PIPoint

```python
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

```python
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

```python
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)
```

[//]: # (### Documentation)

[//]: # (Documentation for tox can be found at [Read The Docs]&#40;https://tox.readthedocs.org&#41;.)

### TODO

- [ ] More utility functions

### Contributing

[//]: # (Contributions are welcome. See [contributing]&#40;https://github.com/tox-dev/tox/blob/master/CONTRIBUTING.rst&#41; and our [Contributor Covenant Code of Conduct]&#40;https://github.com/tox-dev/tox/blob/master/CODE_OF_CONDUCT.md&#41;.)

Currently, the [code](https://github.aepsc.com/s316353/pyPIAF) and the [issues](https://github.aepsc.com/s316353/pyPIAF/issues) are hosted on GitHub.
