Python client library for KaaIoT platform REST APIs.
pip install kaa-rest-clientimport asyncio
from kaa_rest_client import KaaClient, EprClient, EptsClient
async def main():
async with KaaClient(api_key="your-api-key") as kaa:
epr = EprClient(kaa)
endpoints = await epr.list_endpoints(limit=10)
print(endpoints)
epts = EptsClient(kaa)
config = await epts.get_time_series_config()
print(config)
asyncio.run(main())Two authentication methods are supported:
| Method | Header | Env variable |
|---|---|---|
| API key (primary) | x-iamcore-api-key |
KAA_API_KEY |
| Bearer token | Authorization: Bearer ... |
KAA_BEARER_TOKEN |
# API key (recommended)
kaa = KaaClient(api_key="your-api-key")
# Bearer token
kaa = KaaClient(bearer_token="your-token")
# Custom base URL
kaa = KaaClient(base_url="https://your-instance.kaaiot.com", api_key="your-api-key")If both are provided, API key takes precedence.
All service clients use composition — pass a KaaClient instance to the constructor.
Manages endpoints, metadata, filters, and relations.
epr = EprClient(kaa)
# List endpoints
endpoints = await epr.list_endpoints(limit=10, sort="endpointId")
# Register a new endpoint
result = await epr.register_endpoint({"endpointId": "my-device", "applicationName": "my-app"})
# Metadata
metadata = await epr.get_endpoint_metadata("endpoint-id")
await epr.update_endpoint_metadata("endpoint-id", {"key": "value"})
# Filters
filters = await epr.list_filters("my-app")
await epr.create_filter("my-app", {"name": "active-devices", "query": "..."})Invokes commands on endpoints and manages batch operations.
cex = CexClient(kaa)
# Invoke a command
result = await cex.invoke_command("endpoint-id", "reboot", await_timeout=30)
# With payload
result = await cex.invoke_command("endpoint-id", "config", {"brightness": 80})
# Batch command by filter
task = await cex.batch_command_by_filter("reboot", "filter-id")Retrieves time series configuration and data.
epts = EptsClient(kaa)
# Get time series config
config = await epts.get_time_series_config(application_names="my-app")
# Get latest data points
latest = await epts.get_last_time_series("my-app")
# Get historical data
data = await epts.get_time_series_data(
"my-app",
time_series_name="temperature",
from_date="now-7d",
to_date="now",
)Manages endpoint-delivered configurations, application-version defaults, configuration schemas/statuses, and platform-side system configurations.
from kaa_rest_client import EcrClient, KaaClient
async with KaaClient(bearer_token="your-token") as kaa:
ecr = EcrClient(kaa)
result = await ecr.get_endpoint_configuration("endpoint-id", "app-v1")
print(result.data.config)
print(result.etag)Named endpoint-delivered and current system-configuration methods accept an
optional name. When omitted, the client sends name="default"; pass a
configuration name to address a named configuration.
ECR configuration responses encode the config field as a JSON string. The
client parses valid JSON strings into dictionaries, lists, scalar values, or
None; malformed JSON remains the original string. Endpoint configuration
requests are sent as raw JSON bodies.
System configurations can use a DTO, which serializes structured configuration values into the API's string field:
from kaa_rest_client import SystemConfigurationInput
body = SystemConfigurationInput(
name="alert-email-recipients",
display_name="Alert email recipients",
config={"emails": ["alert-monitor@acme.com"]},
)
async with KaaClient(bearer_token="your-token") as kaa:
ecr = EcrClient(kaa)
await ecr.create_application_config("my-app", body)
current = await ecr.get_current_application_config("my-app")
print(current.data.config)System configuration (/system/...) is primarily for static defaults or
platform-side static configuration. Updating it does not directly ship the
configuration to devices over MQTT. Use endpoint/application-version
configuration methods for device-delivered configuration. ECR methods return
an EcrResponse containing data, status_code, and response headers such as
ETag and Location.
Manages ingest pipelines, index templates, and searches documents.
asf = AsfClient(kaa)
# Ingest pipelines
await asf.upsert_pipeline("my-pipeline", {"processors": [...]})
pipeline = await asf.get_pipeline("my-pipeline")
# Search documents
results = await asf.search_documents("tenant-id", "my-app", "2024.01.15", {
"query": {"match_all": {}}
})Manages rules, actions, triggers, alerts, alert settings, and rule execution.
re = ReClient(kaa)
# Rules
rules = await re.list_rules()
rule = await re.get_rule("rule-id")
await re.execute_rule("rule-id")
# Alerts
alerts = await re.list_alerts(entity_type="endpoint", state="OPEN")Manages service instances, applications, application versions, application and tenant configurations, and bulk configuration exports.
tekton = TektonClient(kaa)
applications = await tekton.list_applications()
versions = await tekton.list_app_versions("my-app")
config = await tekton.get_app_config("my-app")
export = await tekton.bulk_export()Manages asset types, assets, and relations between platform entities.
am = AmClient(kaa)
asset_types = await am.list_asset_types()
assets = await am.list_assets()
relations = await am.get_relations("entity-id")Manages tenants, tenant credentials, package types, subscriptions, and user templates.
tenant_manager = TenantManagerClient(kaa)
tenants = await tenant_manager.list_tenants(limit=10)
tenant = await tenant_manager.get_tenant("tenant-id")
credentials = await tenant_manager.get_tenant_credentials("tenant-id")
subscriptions = await tenant_manager.list_subscriptions("tenant-id")You can pass an external httpx.AsyncClient to share connection pools:
import httpx
async with httpx.AsyncClient() as http:
kaa = KaaClient(api_key="key", client=http)
epr = EprClient(kaa)
# ...from kaa_rest_client import KaaApiError, KaaAuthError, KaaNotFoundError
try:
endpoint = await epr.get_endpoint("nonexistent")
except KaaNotFoundError:
print("Endpoint not found")
except KaaAuthError:
print("Authentication failed")
except KaaApiError as e:
print(f"API error {e.status_code}: {e.message}")