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. 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.1.tar.gz (5.3 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.1-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: piafsdkconnect-0.1.1.tar.gz
  • Upload date:
  • Size: 5.3 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.1.tar.gz
Algorithm Hash digest
SHA256 b9ddc6c77ec5c7ab55a335daae5c060b8bf91b8f9f9ace1dd87587a333665e78
MD5 5418270782515f54fab6b3a24a37447b
BLAKE2b-256 88ae3dbd9a63c8e7b5f7afa2d431aa3db0eef27a69d7918d453ecd6e321acc0c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: piafsdkconnect-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.3 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6a5e83a4bff81aacdaaa8164c75bc9d12d2bbd57b5ec4e266f3e2dc346696c07
MD5 f59b83546aa6b0ec718ccf7fe981bf33
BLAKE2b-256 739e27faf11ceeb7d6fe64e42128c0dcf838e3a4440992c10c0e052456c5b31a

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