Example Application Code

The examples below show fully realized examples using the available class methods.

Read/Write example

import asyncio
from random import randint
from inmation_api_client import Client, Options, Item, ItemValue


def create_client():
    client = Client()
    client.Connect('localhost', 8002, Options({
        'auth': {
            'username': 'user',
            'password': 'pass'
        }
    }))
    return client


def main():
    items_path = "/System/Core/"
    items = [
        Item(items_path + 'Item01'),
        Item(items_path + 'Item02')
    ]

    client = create_client()

    # Read items
    res_read = client.Read(items)
    print(res_read['data'])

    write_items = [
        ItemValue(items_path + 'Item01', randint(1, 2**10)),
        ItemValue(items_path + 'Item02', randint(1, 2**10))
    ]

    # Write items
    res_write = client.Write(write_items)
    print(res_write['data'])

if __name__ == '__main__':
    main()

Read Raw Historical Data Example

import asyncio
from datetime import datetime, timedelta
from inmation_api_client import Client, Options, Item, RawHistoricalDataQuery


def create_client():
    client = Client()
    client.Connect('localhost', 8002, Options({
        'auth': {
            'username': 'user',
            'password': 'pass'
        }
    }))
    return client


def main():
    client = create_client()

    now = datetime.now()
    now_minus_month = now + timedelta(-30)
    format = '%Y-%m-%dT%H:%M:%S.000Z'

    start_time = now_minus_month.strftime(format)
    end_time = now.strftime(format)

    path = "/System/Core/"
    items = [
        Item(path + 'Item01'),
        Item(path + 'Item02')
    ]
    queries = [
        RawHistoricalDataQuery(items, start_time, end_time)
    ]
    response = client.ReadRawHistoricalData(queries)
    print(response['data']['historical_data'])

if __name__ == '__main__':
    main()