STTP Python API
Project description
Python STTP (IEEE 2664) Implementation
Streaming Telemetry Transport Protocol
Example Usage
from sttp.subscriber import Subscriber
from time import time
from threading import Thread
def main():
subscriber = Subscriber()
try:
# Start new data read at each connection
subscriber.set_connectionestablished_receiver(
lambda: Thread(target=read_data, args=(subscriber,)).start())
subscriber.subscribe("FILTER TOP 20 ActiveMeasurements WHERE True")
subscriber.connect("localhost:7175")
# Exit when enter key is pressed
input()
finally:
subscriber.dispose()
def read_data(subscriber: Subscriber):
subscriber.default_connectionestablished_receiver()
reader = subscriber.read_measurements()
lastmessage = 0.0
while subscriber.connected:
(measurement, success) = reader.next_measurement()
if not success:
break
if time() - lastmessage < 5.0:
continue
elif lastmessage == 0.0:
subscriber.statusmessage("Receiving measurements...")
lastmessage = time()
continue
message = []
message.append(f"{subscriber.total_measurementsreceived:,}")
message.append(" measurements received so far. Current measurement:\n ")
message.append(str(measurement))
subscriber.statusmessage("".join(message))
lastmessage = time()
Example Output:
Connection to 127.0.0.1:7175 established.
Received 10,742 bytes of metadata in 0.045 seconds. Decompressing...
Decompressed 89,963 bytes of metadata in 0.004 seconds. Parsing...
Parsed 179 metadata records in 0.215 seconds
Discovered:
1 DeviceDetail records
172 MeasurementDetail records
5 PhasorDetail records
1 SchemaVersion records
Metadata schema version: 14
Received success code in response to server command: Subscribe
Client subscribed as compact with 20 signals.
Receiving measurements...
1,470 measurements received so far. Current measurement:
28bbb1fc-3434-48d3-87a8-bf5024c089d5 @ 19:43:53.600 = 516.545 (Normal)
2,970 measurements received so far. Current measurement:
ed6def67-54c4-4e74-af95-c95fa6915fbc @ 19:43:58.600 = 218.070 (Normal)
4,460 measurements received so far. Current measurement:
7aaf0a8f-3a4f-4c43-ab43-ed9d1e64a255 @ 19:44:03.633 = -0.230 (Normal)
5,930 measurements received so far. Current measurement:
7aaf0a8f-3a4f-4c43-ab43-ed9d1e64a255 @ 19:44:08.633 = 8228.000 (Normal)
Connection to 127.0.0.1:7175 terminated.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
sttpapi-0.1.0.tar.gz
(59.1 kB
view details)
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
sttpapi-0.1.0-py3-none-any.whl
(84.8 kB
view details)
File details
Details for the file sttpapi-0.1.0.tar.gz.
File metadata
- Download URL: sttpapi-0.1.0.tar.gz
- Upload date:
- Size: 59.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6da1ec0dbbe8880e93519f9a854347e78d81f6217afc8f121a50bfaf359e7225
|
|
| MD5 |
8e742436858e3e6ebdd1d8b49fec93ec
|
|
| BLAKE2b-256 |
5eb0c72bca81ce42fd29bc827501c2278440ffcdd38114633770a7cbf1975fa0
|
File details
Details for the file sttpapi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sttpapi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 84.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
849812236fad6498da0543b823fc6384f4e1f89eacee5bbed475fbeb8c5ff484
|
|
| MD5 |
f02cd067eb4b113b9eafd4baea93b36f
|
|
| BLAKE2b-256 |
c22e965d237956c72c9c9dc65e6ee26de1d710d7b4f466e28e0b38b84c833cd7
|