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.6.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.6-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: piwebapiconnect-0.1.6.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.6.tar.gz
Algorithm Hash digest
SHA256 044749f23bd0559d1afab9fea0748e650633c63e289681123068928d50a7559c
MD5 ab51a34dee339d09e08e81c53a5393bf
BLAKE2b-256 b311c44f39e53f637b5d38fb93d54970b138f95e639f79562e7212357950fe11

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for piwebapiconnect-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1ff09f3b76c957aca685448e63bd8047138a4082e507365bbab462843fd9b864
MD5 9033f73431f1a47d837cba4918c92278
BLAKE2b-256 e66888ae3098eec67339846dec0a19e1c9df6ebb23c953453ff32d352becf1f9

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