Skip to main content

A professional library for PI Web API integration

Project description

piwebapiconnect

A professional Python library for OSIsoft PI Web API integration. Built cleanly with httpx and asyncio to be purely asynchronous and incredibly robust.

Installation

pip install piwebapiconnect

Setup & Connecting

1. Using a .env file (Recommended)

Create a .env file in your root folder:

PI_WEB_API_URL=https://your-pi-server/piwebapi
PI_WEB_API_USERNAME=domain\user
PI_WEB_API_PASSWORD=your-password
PI_SERVER_NAME=PISERVER01
PI_WEB_API_VERIFY_SSL=False  # Set to True in production
from piwebapiconnect import get_service
service = get_service()

2. Passing credentials directly

import asyncio
from piwebapiconnect import get_service

async def main():
    service = get_service(
        url="https://your-pi-server/piwebapi",
        username="domain\\user",
        password="your-password",
        server_name="PISERVER01",
        verify_ssl=False
    )

    print(await service.test_connection())
    await service.close()

if __name__ == "__main__":
    asyncio.run(main())

Functions Provided

All service functions are asynchronous and must be awaited.

Standard Data Fetching

  • get_current_value(tag_name: str): Fetch the current snapshot value of a tag.
  • get_real_time_data(tag_name: str): An alias for get_current_value.
  • get_recorded_values(tag_name: str, start_time: str, end_time: str): Fetch actual historical recorded values for a time range.
  • get_interpolated_values(tag_name: str, start_time: str, end_time: str, interval: str): Fetch evenly spaced interpolated values (e.g., interval="1h").
  • get_multiple_current_values(tag_names: List[str]): Fetch values for multiple tags simultaneously using high-efficiency StreamSets.
  • get_summary_data(tag_name: str, start_time: str, end_time: str, summary_type: str = "Average"): Get Server-calculated statistics (Average, Minimum, Maximum, Total, etc.).

Live Data Streams

  • get_live_data_stream(tag_name: str, interval_seconds: int = 60): Returns an asynchronous generator yielding live value updates continuously.
    async for data in service.get_live_data_stream("SINUSOID", interval_seconds=5):
        print(data)
    

Data Manipulation

  • write_value(tag_name: str, value: Any, timestamp: Any = None): Write a new value to a PI tag at the specified timestamp.
  • delete_value(tag_name: str, timestamp: str): Delete an exact point from a PI tag.

Metadata & Architecture Options

  • search_tags(query: str): Search for PI tags based on a query pattern (e.g., *temperature*).
  • get_tag_attributes(tag_name: str): Fetch the configuration and metadata associated with a PI point.
  • get_asset_servers(): List available PI AF Asset Servers.
  • get_organizations(asset_server: str): List AF Databases on a specified server.

Utilities

  • test_connection(): Safely verify connection status without throwing exceptions.
  • close(): Cleanly drop the internal async HTTP client connections.

Exception Handling

The library utilizes a custom PIWebAPIError class to safely report network crashes, HTTP errors, and typo issues, preventing your script from shutting down abruptly.

from piwebapiconnect.service import PIWebAPIError

try:
    data = await service.get_current_value("INVALID_TAG_NAME")
except PIWebAPIError as e:
    print(f"PI Database Error: {e}")

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

piwebapiconnect-0.1.7.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

piwebapiconnect-0.1.7-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file piwebapiconnect-0.1.7.tar.gz.

File metadata

  • Download URL: piwebapiconnect-0.1.7.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for piwebapiconnect-0.1.7.tar.gz
Algorithm Hash digest
SHA256 cfde5ab7f665b921d75fbcfa6830f28f8a08734f3a20e2f56a73ae4bb1fbc4eb
MD5 c285dab0d8e76ed59ffc6346a662e8e7
BLAKE2b-256 909d2dfb79b2b13085868095425a9b0257e4b74811ca2ebb5f467ff99f7409d9

See more details on using hashes here.

File details

Details for the file piwebapiconnect-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for piwebapiconnect-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 cd1dea6a9950aea1ad9c085ddb99840cc19ee51ce7ba084e79151f2311c76009
MD5 9c3b4a4e4ec86de8fbbbad8b8b653051
BLAKE2b-256 5d06fd095898dcf53561c89517efb5097e241b66a62493b572c39f90c4cec1dd

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