Skip to main content
SDK

Python SDK for PI Web API

An open-source Python library that handles PI Web API authentication, sessions, pagination, error handling, and pandas conversion so you can focus on your integration logic.

The problem the SDK solves

Every PI Web API integration starts with the same 100 lines of boilerplate: session setup, SSL configuration, retry logic, WebID lookups, pagination handling, digital state detection, and JSON-to-DataFrame conversion. Teams copy-paste this code between projects, each copy drifting slightly and introducing its own bugs.

The PiSharp Python SDK packages all of that into a tested, versioned library. When we fix a bug or add a feature, every project that depends on the SDK gets the improvement via a version bump.

5 lines to first data

Go from zero to reading PI data in under 5 lines. Authentication, sessions, SSL, and connection pooling are handled automatically.

Production-ready defaults

Retry logic with exponential backoff, certificate handling, proper error types, and connection timeout management built in.

pandas-native output

Methods return DataFrames directly with proper timestamp indexing, quality flag filtering, and digital state handling. No manual JSON-to-DataFrame wrangling.

Open source, MIT licensed

Read the source, audit the code, contribute fixes, or fork for your own needs. No vendor lock-in.

Installation

Install from PyPIbash
pip install pisharp-piwebapi

Requirements

DependencyVersion
Python3.9+
requests2.28+
pandas (optional)1.5+ (for DataFrame output)

Kerberos authentication

For Kerberos support, also install pip install requests-kerberos. The SDK detects it automatically and enables Kerberos auth methods.

Quick start

Connect and read your first valuepython
from pisharp_piwebapi import PIWebAPI

# Connect to your PI Web API server
pi = PIWebAPI(
    base_url="https://myserver/piwebapi",
    username="your-username",
    password="your-password",
    # ca_bundle="/path/to/cert.pem",  # Optional: custom CA cert
)

# Read the current value of a PI point
value = pi.points.get_value("sinusoid", server="MY-PI-SERVER")
print(f"Value: {value.value}")
print(f"Timestamp: {value.timestamp}")
print(f"Good: {value.good}")

# Pull recorded history into a pandas DataFrame
df = pi.points.get_recorded(
    "sinusoid",
    server="MY-PI-SERVER",
    start_time="*-24h",
    end_time="*",
)
print(df.describe())
print(f"Rows: {len(df)}, Quality: {df['good'].mean():.1%} good")
Common operationspython
# Find a point by path
point = pi.points.get("sinusoid", server="MY-PI-SERVER")
print(f"WebId: {point.web_id}, Type: {point.point_type}")

# Read interpolated values at fixed intervals
df = pi.points.get_interpolated(
    "sinusoid", server="MY-PI-SERVER",
    start_time="*-7d", end_time="*", interval="1h",
)

# Read summary statistics
summary = pi.points.get_summary(
    "sinusoid", server="MY-PI-SERVER",
    start_time="*-24h",
    summary_types=["Average", "Minimum", "Maximum", "StdDev"],
)

# Write a value
pi.points.write_value("my-output-tag", server="MY-PI-SERVER", value=42.0)

# Batch read current values for many points
values = pi.batch.read_current(web_ids)  # Automatic chunking

What the SDK covers

CapabilityWhat the SDK handles
AuthenticationBasic, Kerberos, and NTLM with automatic session management and connection pooling
SSL / CertificatesCustom CA bundle, Windows cert store integration, certificate validation
Point lookupFind by path, name filter, or search pattern. WebIDs resolved and cached automatically
Reading valuesCurrent, recorded, interpolated, and summary reads with DataFrame output. Digital state handling and quality filtering included
Writing valuesSingle and bulk writes with updateOption and bufferOption support
Batch operationsAutomatic chunking, partial failure detection, and retry for transient errors
PaginationTransparent iteration over paginated responses with truncation warnings
Error handlingTyped exceptions (PIAuthError, PINotFoundError,PIServerError), retry with backoff, and clear error messages

When to use the SDK vs raw requests

Use the SDK when:

You are building a production integration, working on a team project, need reliable error handling, or want DataFrames without manual conversion.

Use raw requests when:

You need to access an endpoint the SDK does not cover, are learning how the API works, or prefer full control over every HTTP detail. The SDK provides a pi.raw_request() escape hatch for this.

How it fits together

GitHub repository

pisharp-piwebapi-python

View the source code, report issues, contribute fixes, and check release notes on GitHub. The README includes the full API reference and changelog.

View on GitHub

Need implementation help?

If you need hands-on help building a PI Web API integration, PiSharp offers quickstart packages, integration audits, and data pipeline sprints.