Skip to main content

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.

Overview

This framework is designed for object-oriented IoT development and is centered around reusable base abstractions for:

  • BaseMqttClient — base class for MQTT clients
  • BaseIot — shared base class for sensors and devices
  • BaseDevice — base class for IoT devices
  • BaseSensor — base class for IoT sensors
  • BaseHub — 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
  • loguru
  • paho-mqtt

Project Structure

  • iot_framework/ — framework package
  • main.py — launcher for IoT processes
  • docker-compose.yml — container setup
  • Dockerfile — image definition
  • load_test.jmx — performance/load testing
  • mosquitto.conf — MQTT broker configuration

License

No license has been specified for this project.

Metadata

Release files for foresttm23-iot 0.1.3.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for foresttm23-iot 0.1.3.5
File Size Uploaded
foresttm23_iot-0.1.3.5.tar.gz 229.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for foresttm23-iot 0.1.3.5
File Interpreter ABI Platform
foresttm23_iot-0.1.3.5-py3-none-any.whl Python 3 none any Details

Total release size: 256.2 kB

Release files / foresttm23_iot-0.1.3.5.tar.gz

Download URL foresttm23_iot-0.1.3.5.tar.gz
Size 229.3 kB
Tags Source
SHA-256 checksum
How to use checksums
23e3206cfdb8bbc9e61bd5f438246f13410cae12af42c09eca11533fb2ed638c
BLAKE2b-256 checksum
How to use checksums
869c8d7789235258355d484a62be8472f1228e5c77b677ffc95f016385de0b3a
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.3.5-py3-none-any.whl

Download URL foresttm23_iot-0.1.3.5-py3-none-any.whl
Size 26.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2c45984b398dbe8ebe13fba51e63ec828255ed4f8cd49aee43f628c0b4f4b88
BLAKE2b-256 checksum
How to use checksums
509f0f9be33db03a3900c1716aa4b52e0808cc6cd7ff18d0323ecd08a0488e53
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 history Release notifications | RSS feed

0.1.5

2 release files

0.1.4

2 release files

This release

0.1.3.5 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page