Skip to main content

Okiff SDK

Project description

okiff-sdk

Python SDK for connecting to and communicating with MQTT brokers. Built as a compiled native extension for high performance and ease of deployment.


Requirements

  • Python 3.9 or later
  • Linux x86-64 (additional platforms coming soon)

Installation

pip install okiff-sdk

No compilation is required. The package is distributed as a pre-built binary wheel.


Quick Start

"""
Example:
    Connect to an MQTT broker, subscribe to a topic,
    publish a message, and receive messages using callbacks.
"""

import time
from okiff_sdk import SDK


# Create SDK instance
sdk = SDK()


# Connection callback
def on_connection(connected: bool, rc: int) -> None:
    """
    Called whenever the connection state changes.

    Args:
        connected: True if connected, False otherwise.
        rc: MQTT return code (0 = success, -1 = unexpected disconnect).
    """
    print(f"[on_connection] connected={connected}, rc={rc}")


# Message callback
def on_message(topic: str, payload: str) -> None:
    """
    Called when a message is received.

    Args:
        topic: MQTT topic.
        payload: UTF-8 message payload.
    """
    print(f"[on_message] topic={topic}, payload={payload}")


# Register callbacks
sdk.on_connection(on_connection)
sdk.on_message(on_message)


# Initialize SDK
sdk.init(
    clientId="clientId",
    brokerHost="ip:port",
    protocol="tcp",
    username="username",
    password="YOUR_JWT_TOKEN",
    cleanSession=True,
    resumeSubs=True,
    connectRetry=True,
    autoReconnect=True,
    connectRetryInterval=5,
    maxReconnectInterval=30,
    keepAlive=30,
    pingTimeout=20,
    writeTimeout=20,
    orderMatters=False,
    connectTimeout=5,
    edition="Enterprise",
)


# Connect
if sdk.connect():
    sdk.subscribe("okiff/sdk/test")
    sdk.publish("okiff/sdk/test", "hello from okiff-sdk")

    # Wait to receive messages
    time.sleep(5)


# Disconnect
sdk.disconnect()
print("Disconnected")

API Reference

SDK()

Creates a new SDK instance.


init(...)

Initializes the MQTT client. L'option edition Enterprise permet à connecter l'IoT Thing to the Cloud Core. For Testing you can use edition Community and connect to Edge/Onpremise Broker core.

This method must be called before connect().

Parameter Type Description
clientId str Unique MQTT client identifier
brokerHost str Broker address with port (host:port)
protocol str Connection protocol ("tcp" or "ssl")
username str MQTT username
password str MQTT password or JWT token
cleanSession bool Start a clean MQTT session
resumeSubs bool Restore subscriptions after reconnect
connectRetry bool Retry the initial connection if it fails
autoReconnect bool Automatically reconnect after disconnect
connectRetryInterval int Initial retry interval (seconds)
maxReconnectInterval int Maximum reconnect interval (seconds)
keepAlive int MQTT keep-alive interval (seconds)
pingTimeout int Ping response timeout (seconds)
writeTimeout int Socket write timeout (seconds)
orderMatters bool Preserve message ordering
connectTimeout int Connection timeout (seconds)
edition str SDK edition (for example "Community" or "Enterprise")

connect() -> bool

Connects to the configured MQTT broker.

Returns True if the connection succeeds.


disconnect()

Gracefully disconnects from the MQTT broker.


publish(topic, payload, qos=0, retained=False)

Publishes a message to the specified topic.

Parameter Type Description
topic str MQTT topic
payload str Message payload
qos int MQTT Quality of Service (0, 1 or 2)
retained bool Publish as a retained message

subscribe(topic, qos=0) -> bool

Subscribes to an MQTT topic.

Returns True if the subscription succeeds.


unsubscribe(topic)

Removes an existing topic subscription.


on_message(callback)

Registers a callback invoked whenever a message is received.

Callback signature:

callback(topic: str, payload: str) -> None

on_connection(callback)

Registers a callback invoked whenever the connection state changes.

Callback signature:

callback(connected: bool, rc: int) -> None

Where:

  • connected=True indicates the client is connected.
  • connected=False indicates the client has disconnected.
  • rc is the MQTT/Paho return code.

is_connected() -> bool

Returns the current connection status.


License

Proprietary — All rights reserved.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

okiff_sdk-1.2.0-cp314-cp314-manylinux_2_39_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.14manylinux: glibc 2.39+ x86-64

okiff_sdk-1.2.0-cp313-cp313-manylinux_2_39_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.39+ x86-64

okiff_sdk-1.2.0-cp312-cp312-manylinux_2_39_x86_64.whl (2.2 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.39+ x86-64

File details

Details for the file okiff_sdk-1.2.0-cp314-cp314-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for okiff_sdk-1.2.0-cp314-cp314-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 b781b8ea6e7a2c685d3f4ff9a0bcb39ed331654c8a59742eea75cdc2aa1591aa
MD5 d919819c53c3d70b0799a9fb67052472
BLAKE2b-256 6cb4a0c1da0e9e7e3bb6ac6ebd10dfaed388b76d96a53c40f46a20b17de3c5a2

See more details on using hashes here.

File details

Details for the file okiff_sdk-1.2.0-cp313-cp313-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for okiff_sdk-1.2.0-cp313-cp313-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 f3259f594776532f84396e71536cb2f64c1514a21995029903a4e894d5432ab1
MD5 23151eb260e0c7665f48f47fe65d7a60
BLAKE2b-256 3cb106664ce566d04b432db77792d7ff6c80bd97fde9fead671a259e7995d142

See more details on using hashes here.

File details

Details for the file okiff_sdk-1.2.0-cp312-cp312-manylinux_2_39_x86_64.whl.

File metadata

File hashes

Hashes for okiff_sdk-1.2.0-cp312-cp312-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 50da30d80746fc396ea75f881b801d3c3d333a6a6fb384dbec845c39270832b0
MD5 10eaea8226ab371a5f55b1b8f124c463
BLAKE2b-256 2fe8d18c0eaacb2c6dba7aee072d7724f5da228311fd8f70cff31487236f7c88

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