Extensible MQTT IoT Communication Framework
A lightweight Python framework for building MQTT-based IoT systems. It provides reusable base classes for hubs, devices, sensors, and MQTT clients, making it easier to implement custom IoT workflows with a consistent architecture.
- PyPI: foresttm23-iot
- Requires: Python 3.13+
Overview
This framework is designed for object-oriented IoT development and is centered around reusable base abstractions for:
BaseMqttClient— base class for MQTT clientsBaseIot— shared base class for sensors and devicesBaseDevice— base class for IoT devicesBaseSensor— base class for IoT sensorsBaseHub— base class for IoT hubs
It also includes a registry system that allows IoT classes to be dynamically discovered and instantiated by their sub_type.
Key Features
- MQTT-based IoT architecture
- Reusable base classes for hubs, devices, and sensors
- Class registry for dynamic IoT type lookup
- Support for custom and extended IoT implementations
- Built-in logging and helper utilities
- Designed to work with an MQTT broker
Core Concepts
Registry System
Use the @register_iot decorator to register your IoT classes:
from iot_framework import BaseDevice, register_iot
@register_iot
class LampDevice(BaseDevice):
sub_type = "lamp"
This registers the class in the framework’s internal registry so it can be instantiated dynamically with get_iot_class().
Base Classes
BaseMqttClient: Provides the shared MQTT client behavior.BaseIot: Adds shared IoT functionality for sensors and devices.BaseDevice/BaseSensor: Specialized implementations for device and sensor behavior.BaseHub: Coordinates devices and sensors, handles discovery, and manages device interactions.
Installation
Install the package from PyPI:
pip install foresttm23-iot
Or install dependencies for local development using the project’s environment setup.
Usage
Run the framework entry point
python main.py <hub_sub_type> <device_sub_type> <sensor_sub_type>
Example:
python main.py hub lamp motion
This launches the requested IoT processes and connects them to the configured MQTT broker.
Example Device
import json
import time
from iot_framework import BaseDevice, logger, register_iot
@register_iot
class LampDevice(BaseDevice):
sub_type = "lamp"
def __init__(self, client, device_id: str):
super().__init__(client, device_id, self.sub_type)
def on_message(self, client, userdata, msg) -> None:
payload = json.loads(msg.payload.decode())
command = payload.get("command").lower()
transaction_id = payload.get("transaction_id")
logger.info(f"📩 [{self.id}] Received command: {command}")
self.set_state(command)
lamp_payload = json.dumps(
{
"state": self.state,
"transaction_id": transaction_id,
"timestamp": time.time(),
}
)
self.client.publish(self.state_topic, lamp_payload, retain=True)
Requirements
- Python 3.13+
- MQTT broker
logurupaho-mqtt
Project Structure
iot_framework/— framework packagemain.py— launcher for IoT processesdocker-compose.yml— container setupDockerfile— image definitionload_test.jmx— performance/load testingmosquitto.conf— MQTT broker configuration
License
This project is licensed under the terms of the MIT License.
Metadata
Release files for foresttm23-iot 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| foresttm23_iot-0.1.4.tar.gz | 230.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| foresttm23_iot-0.1.4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 257.8 kB
Release files / foresttm23_iot-0.1.4.tar.gz
| Download URL | foresttm23_iot-0.1.4.tar.gz |
|---|---|
| Size | 230.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa04fa6ddd04b666663f78d097da548aae9dc68899461c3d0e4f77faa50a45e5
|
|
BLAKE2b-256 checksum How to use checksums |
340d59cb0cda253301b42f166b754a1f7b537579a110993dd390a9c462168638
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / foresttm23_iot-0.1.4-py3-none-any.whl
| Download URL | foresttm23_iot-0.1.4-py3-none-any.whl |
|---|---|
| Size | 27.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c0019c1582275c11b96e6d5da450ef99ef5393d88c24814115e466f8d3f8e7b9
|
|
BLAKE2b-256 checksum How to use checksums |
ee283a91a93d34d4373c13ca15938c439ef161b2fed51cfb4d92cd1cbfd45493
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.24 {"installer":{"name":"uv","version":"0.9.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|