Skip to main content

A professional library for PI AF SDK integration

Project description

piafsdkconnect

A professional Python library for PI AF SDK integration (.NET based).

Installation

pip install piafsdkconnect

Usage

Using .env file

Create a .env file in your project root with the following variables:

PI_SERVER_NAME=YourPIServerName
PI_SDK_PATH=C:\Program Files (x86)\PIPC\AF\PublicAssemblies\4.0  # Optional, defaults to this path
PI_USERNAME=YourUsername  # Optional, for PI User/Windows Auth
PI_PASSWORD=YourPassword  # Optional
from piafsdkconnect import get_service
service = get_service()

Complete Example Usage

Below are examples of how to use each available method in the library.

Initialization

from piafsdkconnect import get_service

# Initialize service with demo credentials
service = get_service(
    server_name="PI_SERVER_DEMO",
    username="domain\\user",
    password="password123",
    sdk_path=r"C:\Program Files (x86)\PIPC\AF\PublicAssemblies\4.0"
)

1. Fetch Current Value

Get the latest snapshot value for a single PI tag.

val = service.get_current_value("SINUSOID")
print(f"Tag: {val['tag']}, Value: {val['value']}, Time: {val['timestamp']}")

2. Fetch Multiple Current Values

Efficiently retrieve values for multiple tags at once.

tags = ["SINUSOID", "CDT158", "BA:LEVEL.1"]
values = service.get_multiple_current_values(tags)
for v in values:
    print(v)

3. Fetch Historical Recorded Values

Get actual stored data points from the PI Archive for a specific time range.

history = service.get_recorded_values("SINUSOID", "*-24h", "*")
for point in history:
    print(f"Time: {point['timestamp']}, Value: {point['value']}")

4. Search for Tags

Find tags on the PI Server using wildcard patterns.

tags = service.search_tags("*water*")
print(f"Found tags: {tags}")

5. Live Data Stream

Yields a continuous stream of data for a list of tags at a specified frequency.

print("Starting live stream (3 iterations)...")
stream = service.get_live_data_stream(["SINUSOID", "CDT158"], frequency=2.5)
for i, data_batch in enumerate(stream):
    print(f"Batch {i+1}: {data_batch}")
    if i >= 2: break

6. Write New Values

Send data to a PI tag at the current time or a specific timestamp.

# Write current value
service.write_value("TEST_TAG", 45.6)

# Write with specific timestamp
service.write_value("TEST_TAG", 99.9, timestamp="2023-10-01 10:00:00")

7. Create New Tag

Create a point on the PI Server with custom attributes.

# Create a tag with default Float32 type
service.create_tag("DEMO_NEW_TAG")

# Create a tag with specific type and descriptor
service.create_tag(
    tag_name="DEMO_TAG_INT", 
    point_type="Int32", 
    descriptor="Demo Integrated System Tag",
    engineeringunits="kPa"
)

8. Asset Server & Organization Lookup

Browse the PI AF hierarchy.

# List AF Asset Servers
servers = service.get_asset_servers()
print(f"Servers: {servers}")

# List Databases for a specific server
dbs = service.get_organizations("AF_SERVER_DEMO")
print(f"Databases: {dbs}")

8. Connection Utilities

# Test connection status
status = service.test_connection()
print(f"Connection Status: {status}")

# Disconnect cleanly
service.disconnect()

License

This project is licensed under the MIT License.

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

piafsdkconnect-0.1.2.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

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

piafsdkconnect-0.1.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file piafsdkconnect-0.1.2.tar.gz.

File metadata

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

File hashes

Hashes for piafsdkconnect-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7a9a57c1f0481196f2b54276628a237cfa12cd51dbc8a51da6c029c395f8dd83
MD5 2fba238fe4ce4a614e935443ce28a742
BLAKE2b-256 9533d09f3e168d15d34d4222949b591b94d9205530bf1bb52b86c569cf152cda

See more details on using hashes here.

File details

Details for the file piafsdkconnect-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: piafsdkconnect-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.6

File hashes

Hashes for piafsdkconnect-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 adff9d57f248dbaf235e950c15859b669608e1963d7ee85772e87b61ae799136
MD5 02c1f1de15cc434ee2af80b29abdb7f3
BLAKE2b-256 4d0dbac17464c1a5d0b7b878033de92d5d13f617f10160e3a08fb84aefb4b598

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