Skip to content

Python

Uses the requests library. Install with pip install requests.

import requests
class VoltaClient:
def __init__(self, api_url: str, api_key: str, layout_id: str):
self.api_url = api_url.rstrip("/")
self.api_key = api_key
self.layout_id = layout_id
self.token = None
def get_layout_info(self) -> dict:
"""Step 1: Discover controls."""
r = requests.get(
f"{self.api_url}/layout/{self.layout_id}",
headers={"x-api-key": self.api_key},
)
r.raise_for_status()
return r.json()
def connect(self):
"""Step 2: Get a token."""
r = requests.post(
f"{self.api_url}/token",
headers={"x-api-key": self.api_key},
json={"layoutId": self.layout_id},
)
r.raise_for_status()
self.token = r.json()["token"]
def send_action(self, lid: int, control_type: str, value=None):
"""Step 3: Send an action."""
payload = {
"layoutId": self.layout_id,
"lid": lid,
"type": control_type,
}
if value is not None:
payload["value"] = value
r = requests.post(
f"{self.api_url}/action",
headers={"Authorization": f"Bearer {self.token}"},
json=payload,
)
r.raise_for_status()
def send_button(self, lid: int):
self.send_action(lid, "Button")
def send_slider(self, lid: int, value: float):
self.send_action(lid, "Slider", value)
def send_toggle(self, lid: int, value: bool):
self.send_action(lid, "Toggle", value)
def send_index(self, lid: int, value: int):
self.send_action(lid, "Index", value)
client = VoltaClient(
api_url="https://your-api-url.execute-api.eu-west-2.amazonaws.com",
api_key="your-api-key",
layout_id="your-layout-id",
)
client.connect()
layout = client.get_layout_info()
# Print available controls
for control in layout["controls"]:
print(f" {control['type']} lid:{control['lid']}{control['props'].get('label', '')}")
# Send interactions
client.send_button(lid=1)
client.send_slider(lid=2, value=0.75)
client.send_index(lid=3, value=1)