IronFlock SDK
The IronFlock SDK lets your edge applications interact with the IronFlock platform. It handles authentication automatically when running on a registered device and provides functions for publishing data, querying history, calling remote procedures across devices, and updating device metadata.
| SDK | Package | Requires |
|---|---|---|
| Python | ironflock on PyPI | Python 3.8+ |
| JavaScript | ironflock on npm | Node.js 18+ or modern browser |
Installation
Python
pip install ironflockOr add ironflock to your app’s requirements.txt.
Quick Start
Python
import asyncio
from ironflock import IronFlock
async def main():
while True:
await ironflock.publish_to_table("sensordata", {
"temperature": 22.5,
"humidity": 60
})
await asyncio.sleep(5)
ironflock = IronFlock(mainFunc=main)
ironflock.run()When used inside an IronFlock app container, the SDK reads connection credentials from the environment automatically — no manual configuration needed.
Constructor Options
Python
ironflock = IronFlock(
mainFunc=main, # async function to run after connecting
serial_number="abc123" # override device serial (optional)
)| Parameter | Description |
|---|---|
mainFunc | An async function that runs once the connection is established |
serial_number | Override the device serial number. Defaults to DEVICE_SERIAL_NUMBER env var |
Publishing Data
publishToTable / publish_to_table
Publishes a data record to a fleet table. The table name must match a table defined in your app’s data-template.yml. The SDK automatically routes the data to the correct project database.
Python
await ironflock.publish_to_table("sensordata", {
"temperature": 22.5,
"humidity": 60,
"device_id": "sensor-001"
})appendToTable / append_to_table
Appends data to a fleet table using a remote procedure call instead of pub/sub. Use this when you need confirmation that the data was persisted.
Python
result = await ironflock.append_to_table("sensordata", {
"temperature": 22.5,
"humidity": 60
})publish
Publishes a message to any WAMP topic. Use this for custom messaging or events that don’t map to a database table.
Python
await ironflock.publish("com.myapp.alerts", {
"level": "warning",
"message": "Temperature threshold exceeded"
})Querying Historical Data
getHistory
Retrieves historical data from a fleet table. Supports filtering, time ranges, and pagination.
Python
# Simple query
data = await ironflock.getHistory("sensordata", {"limit": 100})
# Query with time range and filters
data = await ironflock.getHistory("sensordata", {
"limit": 500,
"offset": 0,
"timeRange": {
"start": "2026-01-01T00:00:00Z",
"end": "2026-03-01T00:00:00Z"
},
"filterAnd": [
{"column": "temperature", "operator": ">", "value": 20},
{"column": "humidity", "operator": "<=", "value": 80}
]
})Query parameters:
| Field | Type | Description |
|---|---|---|
limit | int / number | Maximum rows to return (1–10,000, required) |
offset | int / number | Offset for pagination |
timeRange | dict / object | {"start": "<ISO datetime>", "end": "<ISO datetime>"} |
filterAnd | list / array | AND filter conditions (see below) |
Filter operators: =, !=, >, <, >=, <=, LIKE, ILIKE, IN, NOT IN, IS, IS NOT
Each filter is an object with column, operator, and value keys.
Subscribing to Data
subscribeToTable / subscribe_to_table
Subscribes to real-time updates on a fleet table. The handler is called whenever new data is published to the table.
Python
def on_sensor_data(*args, **kwargs):
print("New reading:", args, kwargs)
await ironflock.subscribe_to_table("sensordata", on_sensor_data)subscribe
Subscribes to any WAMP topic for custom real-time messaging.
Python
def on_alert(*args, **kwargs):
print("Alert received:", args, kwargs)
await ironflock.subscribe("com.myapp.alerts", on_alert)Cross-Device Communication
registerDeviceFunction / register_device_function
Registers a procedure that other devices in the same project can call. The SDK automatically namespaces the procedure to the current device.
Python
def add(a, b):
return a + b
await ironflock.register_device_function("com.myapp.add", add)
register()is an alias forregister_device_function().
callDeviceFunction / call_device_function
Calls a procedure registered by another device. The SDK assembles the full WAMP topic automatically using the target device’s key.
Python
result = await ironflock.call_device_function(
42, # target device key
"com.myapp.add", # procedure name
args=[3, 5] # arguments
)
print(result) # 8call
Calls a remote procedure using a full WAMP URI. Use this for direct calls when you know the exact topic.
Python
result = await ironflock.call("some.full.wamp.topic", args=[42])Device Metadata
setDeviceLocation / set_device_location
Updates the device’s GPS location in the platform. Changes are reflected in real time on IronFlock maps.
Python
await ironflock.set_device_location(long=8.6821, lat=50.1109)| Parameter | Range |
|---|---|
long | -180 to 180 |
lat | -90 to 90 |
Location history is not stored. To track location over time, create a dedicated table and use
publish_to_table/publishToTable.
getRemoteAccessUrlForPort
Returns the public remote access URL for a given port on the device.
Python
url = ironflock.getRemoteAccessUrlForPort(8080)
# "https://<device_key>-<app_name>-8080.app.ironflock.com"Connection Properties & Lifecycle
Python
| Property | Type | Description |
|---|---|---|
is_connected | bool | Whether the platform connection is active |
connection | CrossbarConnection | The underlying connection instance (advanced use) |
| Method | Description |
|---|---|
run() | Starts the connection and runs mainFunc (blocking) |
await start() | Starts the connection asynchronously |
await stop() | Stops the connection and cancels running tasks |
await run_async() | Starts and keeps the connection running asynchronously |
Browser Usage (JavaScript only)
The JavaScript SDK works in modern browsers. Since browsers don’t have environment variables, pass all config via the constructor:
import { IronFlock } from "ironflock";
const ironflock = new IronFlock({
serialNumber: "device-serial-from-server",
deviceKey: "my-device-key",
appName: "MyWebApp",
swarmKey: 10,
appKey: 20,
env: "PROD",
});
await ironflock.start();
await ironflock.publishToTable("sensordata", [{ temperature: 22 }]);Use IronFlock.fromServer() to fetch configuration from your backend instead of hardcoding credentials:
const ironflock = await IronFlock.fromServer("/api/ironflock-config");
await ironflock.start();Your backend endpoint should return a JSON object with the connection options (serialNumber, deviceKey, appName, swarmKey, appKey, env).
Registering AI Agent Functions
The SDK can register functions that are callable by AI agents. Register a procedure and reference its topic in your ai-template.yml:
Python
def get_sensor_reading(sensor_id):
"""Returns the latest reading from a sensor."""
reading = read_from_hardware(sensor_id)
return {
"sensor_id": sensor_id,
"temperature": reading.temp,
"humidity": reading.hum,
"timestamp": reading.ts
}
await ironflock.register_device_function("sensors.get_latest", get_sensor_reading)The AI agent can then call this function when a user asks a question that requires live sensor data.
To wire the registered WAMP topic to an AI agent, reference it in your app’s .ironflock/ai-template.yml:
sensor_agent:
tool_description: |
Delegate to this agent when the user asks about sensor readings,
live device data, or current environmental conditions.
system_prompt: |
You are a sensor data specialist. Use get_current to retrieve
the latest reading from any sensor. Always include the unit in
your response.
main: true
max_context_tokens: 30000
max_iterations: 5
tools:
get_current:
description: Returns the latest reading from a sensor.
topic: sensors.get_latest
parameters:
sensor_id:
type: string
description: The sensor identifier to query.
required: trueThe topic value (sensors.get_latest) must match the name passed to register_device_function / registerDeviceFunction in your edge code. IronFlock automatically routes the call to the device where the function is registered.
For the full ai-template.yml reference, see Defining Agents & Tools.
Environment Variables
These variables are set automatically by the IronFlock runtime inside app containers:
| Variable | Description |
|---|---|
DEVICE_NAME | Device display name |
DEVICE_SERIAL_NUMBER | Unique, immutable device identifier |
DEVICE_KEY | Device key for authentication |
SWARM_KEY | Project identifier |
APP_KEY | App identifier |
APP_NAME | App name |
ENV | Environment: DEV or PROD |
Python
import os
device_name = os.environ.get("DEVICE_NAME")
serial = os.environ.get("DEVICE_SERIAL_NUMBER")
project_key = os.environ.get("SWARM_KEY")Environment Variables
These variables are set automatically by the IronFlock runtime inside app containers:
| Variable | Description |
|---|---|
DEVICE_NAME | Device display name |
DEVICE_SERIAL_NUMBER | Unique, immutable device identifier |
SWARM_KEY | Project identifier |
APP_KEY | App identifier |
import os
device_name = os.environ.get("DEVICE_NAME")
serial = os.environ.get("DEVICE_SERIAL_NUMBER")
project_key = os.environ.get("SWARM_KEY")