Skip to main content

Python client for the TIREMO SDK REST and live WebSocket APIs

Project description

tiremo-sdk-client

Async Python client for the TIREMO SDK. REST bootstrap plus a WebSocket live channel for telemetry, presence, and alarms.

Requires Python 3.10+.

Documentation

Topic Link
SDK Live Data docs.tiremo.ai/developer-guide/sdk-live-data
API Key Security docs.tiremo.ai/developer-guide/sdk-api-key-security

Getting started

1. Install

pip install tiremo-sdk-client

From source (development):

cd client-python
make venv lint

2. Get an API key

Create a product-scoped API key in the Tiremo Platform Administration → API Credentials UI.

Use a secret key for backend services. Use create_live_token() when handing off to untrusted clients.

3. Create a client

from tiremo_sdk import TiremoClient

client = TiremoClient(
    api_key="your-api-key",
    base_url="https://sdk.tiremo.ai",
)

All methods are async — run them inside asyncio.run() or your async framework.

4. Choose a live connection mode

Method When to use
connect_live_with_secret_key() Trusted backend scripts and workers
create_live_token() + connect_live_with_token() Serving browser or mobile clients

Usage examples

TiremoClient — REST

get_telemetry_latest(device_identifier, *, keys=None)

latest = await client.get_telemetry_latest(
    "cameradevice9",
    keys=["temperature", "humidity"],
)

print(latest["deviceIdentifier"])
print(latest["timestamp"])
print(latest["data"]["temperature"])

Pass keys=None to fetch all keys on the latest point.

create_live_token()

token_response = await client.create_live_token()
token = token_response["token"]
expires_at = token_response["expiresAt"]

connect_live_with_token(token)

live = client.connect_live_with_token(token)
await live.connect()

connect_live_with_secret_key()

live = client.connect_live_with_secret_key()
await live.connect()

TiremoLiveClient — WebSocket

connect() / disconnect()

await live.connect()
# ...
await live.disconnect()

on(event, handler)

Handlers may be sync or async. Returns an unsubscribe callable.

async def on_telemetry(event: dict) -> None:
    print(event["data"])

live.on("telemetry", on_telemetry)

live.on("connected", lambda e: print(e["productIdentifier"]))
live.on("presence", lambda e: print(e["deviceIdentifier"], e["isOnline"]))
live.on("alarm", lambda e: print(e["alarmType"], e["severity"]))
live.on("error", lambda e: print(e["code"], e["message"]))

subscribe_telemetry(subscription_id, device_identifier, *, keys=None)

await live.subscribe_telemetry(
    "temp-sub",
    "cameradevice9",
    keys=["temperature"],
)

subscribe_presence(subscription_id, device_identifier)

await live.subscribe_presence("presence-sub", "cameradevice9")

subscribe_alarm(subscription_id, device_identifier)

await live.subscribe_alarm("alarm-sub", "cameradevice9")

unsubscribe(subscription_id)

await live.unsubscribe("temp-sub")

Ping/pong heartbeats are handled automatically.

Full example

import asyncio

from tiremo_sdk import TiremoClient


async def main() -> None:
    client = TiremoClient(
        api_key="your-api-key",
        base_url="https://sdk.tiremo.ai",
    )

    latest = await client.get_telemetry_latest("cameradevice9", keys=["temperature"])
    print("Latest:", latest["data"])

    live = client.connect_live_with_secret_key()

    async def on_connected(_event: dict) -> None:
        await live.subscribe_telemetry("temp", "cameradevice9", keys=["temperature"])

    async def on_telemetry(event: dict) -> None:
        print("Live:", event["data"])

    live.on("connected", on_connected)
    live.on("telemetry", on_telemetry)

    await live.connect()
    await asyncio.sleep(60)
    await live.disconnect()


asyncio.run(main())

Related packages

Package Use case
@empa-electronics/tiremo-sdk-client-js Browser / bundler
@empa-electronics/tiremo-sdk-client-node Node.js 18+

License

ISC — Empa Electronics

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

tiremo_sdk_client-0.1.4.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

tiremo_sdk_client-0.1.4-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file tiremo_sdk_client-0.1.4.tar.gz.

File metadata

  • Download URL: tiremo_sdk_client-0.1.4.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for tiremo_sdk_client-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c8908d7d2d8aa5124b272853353c8f1087c5d6ee60be33d25964bb0a846d5534
MD5 a8d7cf0f03788f7c64b27b75f642ea92
BLAKE2b-256 7857ed61202e2a4515e63a81b6d60ba03a6a5b900ab1857732c47b8ef09513a9

See more details on using hashes here.

File details

Details for the file tiremo_sdk_client-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for tiremo_sdk_client-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 9a7d559d3e46732443d4a1e8565f65b6e30e23a4f878ca44532f320fc62f8619
MD5 28072539ebf4c57853d2c4290574a1f4
BLAKE2b-256 f71af421cd084b01f91d94b1ef4ffa3a7b0feff8d3d68b661e0a0cf84be6473d

See more details on using hashes here.

Supported by

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