Get a Device
This example demonstrates how to retrieve a device from the ActionStreamer API using the official Python library.
Prerequisites
- Python 3.7+
- The
actionstreamerPython package installed (e.g., viapip install actionstreamer) - Access and secret keys saved to the local file system
File Setup
Save your access key and secret key in text files:
AccessKey.txtSecretKey.txt
Store these files in a local configuration folder, for example:
C:\temp\config\(Windows)/tmp/config/(Linux/macOS)
Example Code
from actionstreamer import Config
from actionstreamer import WebService
# Save your access key and secret key to AccessKey.txt and SecretKey.txt somewhere on the file system.
if Config.is_windows():
config_folder_path = 'C:\\temp\\config\\'
else:
config_folder_path = '/tmp/config/'
access_key = Config.get_config_value(config_folder_path, "AccessKey")
secret_key = Config.get_config_value(config_folder_path, "SecretKey")
web_service_base_url = 'https://api.actionstreamer.com/'
ws_config = Config.WebServiceConfig(access_key, secret_key, web_service_base_url, 10, False)
serial_number = 'TestDevice'
device_result = WebService.Device.get_device(ws_config, serial_number)
if device_result.code == 200:
device = device_result.device
print('DeviceID: ' + str(device.key))
print('Serial number: ' + device.serial_number)
print('Device name: ' + device.device_name)