API client for system:inmation.
Project description
inmation API Client
This API client can only be used with the new inmation Web API server.
Installation
Install with pip install inmation-api-client
.
Dependencies
- websockets, added to the requirements in setup.py.
Usage
import asyncio
from inmation_api_client import Client, Options, Item
def create_api_client(ioloop):
WS_URL = 'ws://127.0.0.1:8000/ws'
OPTIONS = Options("USERNAME", "PASSWORD")
client = Client(ioloop)
ioloop.run_until_complete(client.connect_ws(WS_URL, OPTIONS))
def connection_changed(conn_info):
""" closure """
print('Connection state: {}, authenticated: {}'.format(conn_info.state_string, conn_info.authenticated))
client.on_ws_connection_changed(connection_changed)
def on_error(err):
if err:
print("Error: {}".format(err.message))
client.on_error(on_error)
return client
EVENT_LOOP = asyncio.get_event_loop()
CLIENT = create_api_client(EVENT_LOOP)
async def read_items_at_once(items):
def read_cbk(*args):
"""read items callback"""
err = args[0]
if err:
print(err.message)
else:
_items = args[1]
if isinstance(_items, list):
print("{} - {}".format('Item', 'Value'))
for item in _items:
if 'error' in item:
print('Error: {}'.format(item['error']['msg']))
else:
item_val = item['v'] if 'v' in item else 'No Value'
print("{} - {}".format(item['p'], item_val))
await CLIENT.read(items, read_cbk)
def main():
items_path = "/System/Core/"
items = [
Item(items_path + 'Item01'),
Item(items_path + 'Item02'),
Item(items_path + 'Item03'),
]
# Read items
EVENT_LOOP.run_until_complete(read_items_at_once(items))
if __name__ == '__main__':
main()
inmation
inmation is a vendor-independent industrial system-integration specialist. Dedicated to modern technologies such as OPC UA (Unified Architecture) and document-oriented schema-less repositories, inmation opens up new horizons for enterprise real-time data management.
More information on inmation.com
License
MIT
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
inmation-api-client-0.2.3.tar.gz
(21.3 kB
view hashes)
Close
Hashes for inmation-api-client-0.2.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29bdd31053b23b828517d9c3f20d135dbf3bcc938920a23712e2ac4cff589ef9 |
|
MD5 | ac12e97fcac20cd1f3c8604c10d5c9e1 |
|
BLAKE2b-256 | d15ec4d5f5dcbb2098ed527219ab8b11debeca84033ef608c8ad415ed543396b |