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 Tags (Batch)
Create multiple points on the PI Server efficiently in a single operation.
# Configuration for multiple tags
new_tags = [
{"tag_name": "DEMO_TAG_1", "point_type": "Float32", "descriptor": "First Batch Tag"},
{"tag_name": "DEMO_TAG_2", "point_type": "Int32", "engineeringunits": "bar"},
{"tag_name": "DEMO_TAG_3"} # Uses default Float32
]
# Create tags and get status for each
results = service.create_tags(new_tags)
for tag, success in results.items():
print(f"Tag {tag} creation: {'Success' if success else 'Failed'}")
# You can still create a single tag
service.create_tag("SINGLE_DEMO_TAG", point_type="String")
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file piafsdkconnect-0.1.3.tar.gz.
File metadata
- Download URL: piafsdkconnect-0.1.3.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a66d2cf0f3249f2481e44e483267b01b3194a833d8495d2a7e1a586f0600d45b
|
|
| MD5 |
a1a88aab2674218da360ab541e3174cf
|
|
| BLAKE2b-256 |
41582708729ddd41753e7a8de0f736cda835e34b5d4adcbe8089317664d90532
|
File details
Details for the file piafsdkconnect-0.1.3-py3-none-any.whl.
File metadata
- Download URL: piafsdkconnect-0.1.3-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7ba2125cd5f5332f02401f0ea246982198d69906cded1db8c489a5534e938688
|
|
| MD5 |
3ee3ce4f9f871890b6718e7fc2cd51d3
|
|
| BLAKE2b-256 |
8f6de824b960c252e9bd15d655f70876802985228b77771c9923164151e508f6
|