Skip to main content

HTTP Python Wrapper for Synaccess SynLink PDU HTTP API.

Project description

SynLink Python Library

About

SynLink Python Library is a Python interface for the SynLink Smart PDU API.

Installation

$ pip install synlinkpy

Examples

from synlinkpy import SynLinkPy

pdu1 = SynLinkPy("http://192.168.1.100", { "username": "admin", "password": "admin" })

# Change outlet state for a given PDU (Power Distribution Unit)
pdu1.outlets.set_state("1", "OFF") # accepts outlet number
pdu1.outlets.set_state("1-1200578", "ON") # accepts unique outlet ID
pdu1.outlets.set_state("2", "REBOOT") # acceptable states are "OFF", "ON", "REBOOT"

# Get information of all outlets
outlet_response = pdu1.outlets.list()
for outlet in outlet_response:
    print(outlet['id'], outlet['outletName'], outlet['state'])

# Get information on inlet(s)
inlet_response = pdu1.inlets.list()

for inlet in inlet_response:
    print(inlet['id'], inlet['inletCurrentRms'], inlet["inletVoltageRms"])


# Modify Configuration 
# https://synaccess.com/support/webapi#configuration
pdu1.conf.set({"lcdOutletControlEnabled": False})

HTTP API Documentation

https://synaccess.com/support/webapi

Authentication

Authentication can occur with Personal Access Token (PATs) or Username & Password. It is recommended to use Personal Access Tokens.

Authenticating with Username and Password

pdu1 = SynLinkPy("http://192.168.1.100", { "username": "admin", "password": "admin" })

print(pdu1.device.info())

Authenticating with Personal Access Token

pdu1 = SynLinkPy("http://192.168.1.100", { "token": "9wxBwnck6JpEH0b1DyI" })

print(pdu1.device.info())

Python Library Commands

Outlet Commands

Outlet API Information https://synaccess.com/support/webapi#outlets

pdu1 = SynLinkPy("http://192.168.1.100", { "username": "admin", "password": "admin" })

# Change outlet state for a given PDU (Power Distribution Unit)
pdu1.outlets.set_state("1", "OFF") # accepts outlet number
pdu1.outlets.set_state("1-1200578", "ON") # accepts unique outlet ID
pdu1.outlets.set_state("2", "REBOOT") # acceptable states are "OFF", "ON", "REBOOT"

# Change outlet name for a given PDU
pdu1.outlets.change_config("1", { "outletName": "example name" })

# Get information of all outlets
outlet_response = pdu1.outlets.list()

for outlet in outlet_response:
    print(outlet['id'], outlet['outletName'], outlet['state'])

# OUTPUT
# 1-1200578 Outlet 1 ON
# 2-1200578 Rectifier #1 ON
# 3-1200578 Outlet 3 ON
# 4-1200578 Outlet 4 ON

Inlet Commands

Inlet API Information https://synaccess.com/support/webapi#inlets

pdu1 = SynLinkPy("http://192.168.1.100", { "username": "admin", "password": "admin" })

inlet_response = pdu1.inlets.list()
for inlet in inlet_response:
    print(inlet['id'], inlet['inletPlug'], inlet['inletCurrentRms'] )

# OUTPUT
# I1-1000036 0.0 117.4000015258789

Bank Commands

Bank API Information https://synaccess.com/support/webapi#banks

pdu1 = SynLinkPy("http://192.168.1.100", { "username": "admin", "password": "admin" })

banks_response = pdu1.banks.list()

for bank in banks_response:
    print(bank['id'], bank['currentRms'])

# OUTPUT
# 1200578 0.0

Device Commands

Device API Information https://synaccess.com/support/webapi#device

pdu1 = SynLinkPy("http://192.168.1.100", { "username": "admin", "password": "admin" })

device_response = pdu1.device.info() 

print (device_response['modelNumber'], device_response['enclosureSerialNumber'], device_response['formFactor'])

# OUTPUT
# 5001AIE-0E 1000036 Compact

Groups Commands

Groups API Information https://synaccess.com/support/webapi#groups

pdu1 = SynLinkPy("http://192.168.1.100", { "username": "admin", "password": "admin" })

groups_response = pdu1.groups.list()
for group in groups_response:
    print(group['id'], group['groupName'], group["outlets"])

# OUTPUT
# 1 Example Group [...] 
# 2 Important Equipment [...]
# 3 Non Essential Equipment [...]

# Create new group with name, to add outlets use groups.modify
pdu1.groups.create("Example Name")

# outlets value must be an array and will override pre-existing outlet's value. First argument is group ID
pdu1.groups.modify(1, { "outlets": ["1-200578", "3-200578"] })

# switch all outlets of the group, will switch according to sequencing time setting
pdu1.groups.set_state(1, "OFF")

# permanently remove based off of group ID
pdu1.groups.delete(1)

Configuration Commands

Configuration API Information https://synaccess.com/support/webapi#configuration

pdu1 = SynLinkPy("http://192.168.1.100", { "username": "admin", "password": "admin" })

conf_response = pdu1.conf.list()
print(conf_response["macAddr"], conf_response["deviceName"], conf_response["lcdOrientation"])

# OUTPUT
# 0C:73:EB:BE:00:27 Demo Compact PDU 90

# Set configuration with key value pairs
pdu1.conf.set({ "lcdOutletControlEnabled" : False })

Sensors Commands

Sensors API Information https://synaccess.com/support/webapi#sensors

pdu1 = SynLinkPy("http://192.168.1.100", { "username": "admin", "password": "admin" })

sensors_response = pdu1.sensors.list()
for sensor in sensors_response:
    print(sensor['sensorPort'], sensor['sensorName'], sensor['sensorTempInC'], sensor['sensorHumidity'])

# OUTPUT
# B Temperature & Humidity Sensor 22.9057 39.50677

Event & Action Commands

Events API Information https://synaccess.com/support/webapi#events

Actions API Information https://synaccess.com/support/webapi#actions

pdu1 = SynLinkPy("http://192.168.1.100", { "username": "admin", "password": "admin" })

# List all events
event_response = pdu1.events.list()
for events in event_response:
    print(events['id'], events['name'], events['code'], events['params'], events['actions'], events['triggered'])
# OUTPUT
# 1 Example High Current Event for Bank #1 31 ['2003757', '16', '10'] [] False


# List all actions
action_response = pdu1.actions.list()
for actions in action_response:
    print(actions['id'], actions['name'], actions['code'], actions['params'])
# OUTPUT
#1 Example Power Cycle for Outlet #1 12 ['1-2003757', '', '']

# Create an action
example_action = pdu1.actions.create({ "name": "example reboot", "code": 12, "params": ["1-2003757","",""] })

# Create an event
example_event pdu1.events.create({"name": "example outlet current event", "code": 46, "params": ["1-2003757", "0.2", "3"], "actions": []})

# Modify an event
pdu1.events.modify(example_event['id'], "actions": [example_action['id']])

# Modify an action
pdu1.actions.modify(example_action['id'], { "name": "example reboot 2", "code": 12, "params": ["2-2003757","",""] })

# Delete an event
pdu1.events.delete(example_event['id'])

# Delete an action
pdu1.actions.delete(example_action['id'])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

synlinkpy-0.0.13.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

synlinkpy-0.0.13-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file synlinkpy-0.0.13.tar.gz.

File metadata

  • Download URL: synlinkpy-0.0.13.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for synlinkpy-0.0.13.tar.gz
Algorithm Hash digest
SHA256 f0179b433ba7f1af314dcb2b11e403697ce0e6932a4180adb20a64cea5c2161d
MD5 dce682ff461d62407a4d55ee76d76f58
BLAKE2b-256 2143ac386e105e05f63af757291c039ee905454c5d3cada206b4edece78c7170

See more details on using hashes here.

File details

Details for the file synlinkpy-0.0.13-py3-none-any.whl.

File metadata

  • Download URL: synlinkpy-0.0.13-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for synlinkpy-0.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 9e4d6ace9a2cab72f4019bce6848e353fe876f3c0218a9ef5b3913449ae84b26
MD5 f13f173cdf26a4ef08f0a7eb5c42d151
BLAKE2b-256 724bb189a7d58ae25e06e6936f81c1dc74e889e2e89c879fca9882dd15d4e933

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page