Python language examples of using the TRASSIR SDK

The Python as the easiest programming language is used in the examples on this page. These examples should run as a standalone program unlike the examples described in administrator guidance. Install Python to run.

Although the SDK is designed to be used in applications, all of its functions work from a browser. Moreover, the SDK comments suggest additional functions that may be called. All you have to do is copy the example to the address bar. Try out all the functions using a browser!

The TRASSIR SDK functions require either an SDK password or a session ID. Use your password instead of "123" in the examples.

/login lets you receive a session ID if you have a password. For most of the SDK functions, it does not matter if you pass a session ID or directly pass a password. Only functions for getting events change their behavior: given a password, they return all recent events; given a session ID, then return only new events.

/objects lets you get the object tree and find objects within TRASSIR, for example all of the channels.

import urllib, re, ssl
s = urllib.urlopen("https://127.0.0.1:8080/objects/?password=12345", context=ssl._create_unverified_context()).read()
for x in s.replace("\n", "").split("{"):
    m = re.search('"name"\s*\:\s*"(.*?)".*Channel', x)
    if not m: continue
    print m.group(1) 

The example removes all newline characters ("\n") from the string, uses a delimiter ("{") to split the result into a list of strings, and searches each of them for "name" : "NAME" ... Channel using a regular expression. If an instance is found, NAME is printed.

/objects/id.object lets you examine the state of an object. You can view an object's possible states in the rule editor and class description.

/objects/id.object/method?param1=val1&param2=val2 lets you call a method on an object. You can find an object's identifier in the object tree. You can find the names of methods and parameters in the rule editor or class description.

/classes/id.class lets you view the states of objects of a given class as well as available methods, including the names and types of parameters.

/settings/folder/field lets you read and write settings. TRASSIR settings are divided into folders containing fields that are one of three types: integer, real, or string. You can view the names of folders and fields by pressing F4 in the administrator's interface. This mode lets you view and edit settings while avoiding settings dialog boxes. This mode lets you experiment to see how the system will behave given any particular change to the settings.

If the field name is omitted in the request, the SDK will return a list of available fields and subfolders.

/events lets you get system events. In the response, "timestamp" uses UNIX time in microseconds. You can view the possible event types in the rule editor. The "origin" field contains the object's identifier. You can get the object's name and other properties from the object tree. Some events contain additional fields. For example, the "Connected to %1 under %2" event contains two fields: "server_address" and "under_username".

import urllib, re
s = urllib.urlopen("https://localhost:8080/login?password=123").read()
sid = re.search('"sid"\s*:\s*"(.*?)"', s).group(1)
print "my session: %s" % sid
while 1:
    s = urllib.urlopen("https://127.0.0.1:8085/events?sid=%s" % sid).read()
    print s 

This example receives and prints events as they come in.

/pos_events lets you get POS events in a similar manner. The event format is exactly the same as ActivePOS events in scripts.

/lpr_events lets you get AutoTRASSIR events in a similar manner. The event format is exactly the same as AutoTRASSIR events in scripts.