Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Kamio v1.0.0b4

Python Version Version License MQTT Coverage Tests

Kamio is a declarative asynchronous IoT framework for Python built on MQTT. Describe your devices as classes, connect hardware with drivers, and automate with rules.

Features

  • Declarative devices — state, telemetry, event, config fields via Python annotations
  • Drivers — GPIO, Serial, Telnet, HTTP, UDP, Modbus TCP, Mock (latency/failure simulation)
  • MQTT v5 — reliable communication, auto-reconnect, backward compatibility with legacy topics
  • Asynchronous — fully asyncio, no blocking calls in the event loop
  • Automation rules — react to field changes and periodic intervals
  • Plugin System — isolated plugins with automatic cleanup via PluginContext
  • Hot-Reload — reload rules and devices without stopping the application
  • Custom MQTT Nodes — arbitrary MQTT nodes with message routing
  • Home Assistant Discovery — lazy-init, activated only when enable_ha_discovery() is called
  • Configuration — JSON files + Kamio_* environment variables

Installation

pip install kamio

Requirements

  • Python 3.10+
  • MQTT broker (Mosquitto recommended)
# Ubuntu/Debian
sudo apt-get install mosquitto mosquitto-clients
# macOS
brew install mosquitto
# Windows: https://mosquitto.org/download/

Additional Dependencies

pip install kamio[gpio]           # GPIO (gpiod)
pip install kamio[serial]          # Serial (pyserial)
pip install kamio[http]            # HTTP (aiohttp)
pip install kamio[all-drivers]   # all external driver dependencies (gpiod, pyserial, aiohttp)
pip install kamio[dev]            # formatting, type checking
pip install kamio[test]           # pytest, pytest-asyncio

UDPDriver, TelnetDriver, and ModbusTCPDriver use only the Python standard library and are available without extras.

Quick Start

import asyncio
from kamio import KamioApp, Device, command, state, telemetry

app = KamioApp(mqtt_broker="mqtt://localhost:1883")


class SmartLight(Device):
    power:      bool  = state(default=False, writable=True)
    brightness: int   = state(default=100, min=0, max=255, writable=True)
    energy_wh:  float = telemetry(default=0.0, unit="Wh")

    @command
    async def toggle(self):
        self.power = not self.power
        return {"power": self.power}


class MotionSensor(Device):
    motion_detected: bool = state(default=False, writable=True)


@app.rule(device=MotionSensor, fields=["motion_detected"])
async def on_motion(event, app):
    if event.data["motion_detected"]:
        light = app.devices.get("living_room")
        if light:
            await light.handle_state({"power": True, "brightness": 200})


async def main():
    # You can pass a driver: Serial/Telnet/HTTP/UDP/Modbus TCP
    # await app.add_device("living_room", SmartLight, driver=TelnetDriver("10.0.0.10"))
    await app.add_device("living_room", SmartLight)
    await app.add_device("hall_sensor", MotionSensor)
    await app.start()


if __name__ == "__main__":
    asyncio.run(main())
    # OR blocking startup with SIGINT/SIGTERM handling:
    # app.run()

Usage Examples

Plugins

from kamio.plugins.builtin.metrics_plugin import MetricsPlugin

metrics = await app.load_plugin(MetricsPlugin)
print(metrics.get_counter("device_state_changed"))

Hot-reload rules

app.watch_directory("rules/", "*.py", app.hot_reload.make_rules_handler())
app.enable_hot_reload()

Home Assistant Discovery

app.enable_ha_discovery(prefix="homeassistant")
# HADiscovery is created only here, not during KamioApp initialization

Custom MQTT node

from kamio.core.custom_nodes import CustomNode

class BridgeNode(CustomNode):
    async def handle_message(self, topic: str, payload: bytes):
        print(f"Bridge received: {topic}")

app.register_custom_node("bridge", BridgeNode(app.mqtt_client, "bridge"))

Configuration via file

app = KamioApp(config_path="config.json")
{
  "mqtt_broker": "mqtt://broker.local:1883",
  "log_level": "INFO"
}

Or via environment variables:

Kamio_MQTT_BROKER=mqtt://broker.local:1883
Kamio_LOG_LEVEL=DEBUG

Test Structure

tests/
  unit/         # isolated component tests (751 tests, 94% coverage)
  stress/       # load tests (16 tests)
pytest                          # all tests
pytest tests/unit/              # unit only
pytest tests/stress/            # stress only
pytest --cov=kamio              # with coverage report

Documentation

  • API — reference for all classes and methods v1.0.0b4
  • Architecture — detailed architecture overview v1.0.0b4
  • CHANGELOG — changelog

License

Apache-2.0 — see the LICENSE file

Metadata

Release files for kamio 1.0.0b4

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

Source distribution (sdist)

Source distribution for kamio 1.0.0b4
File Size Uploaded Provenance Actions
kamio-1.0.0b4.tar.gz 84.8 kB Without provenance Details for kamio-1.0.0b4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kamio 1.0.0b4
File Interpreter ABI Platform Actions
kamio-1.0.0b4-py3-none-any.whl Python 3 none any Details for kamio-1.0.0b4-py3-none-any.whl

Total release size: 188.6 kB

Release files / kamio-1.0.0b4.tar.gz

Download URL kamio-1.0.0b4.tar.gz
Size 84.8 kB
Tags Source
SHA-256 checksum
How to use checksums
579c18482477072549ff5e49ebb9c2421ad6aae1395b9696e4cbdbc1f761e782
BLAKE2b-256 checksum
How to use checksums
3b7dca6d354d30a2c7f525d1121bf12dc98c61fbb4618f61b7c0202455b93555
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Release files / kamio-1.0.0b4-py3-none-any.whl

Download URL kamio-1.0.0b4-py3-none-any.whl
Size 103.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
81d8fe59a2c8b1aa62d80e4c779cca277feba6abfc6892161e6d7cce5458d30d
BLAKE2b-256 checksum
How to use checksums
34c5eee60e68d42e831fcf495d4c3bab4a207393ac6e8ca0fc4355e586c07d6c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.13

Security for kamio 1.0.0b4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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