Django DeviceHub¶
Declarative IoT device management for Django.
Django DeviceHub lets you define IoT device types as Python classes and automatically generates Django models, REST API endpoints, admin interfaces, MQTT topic structures, and broker authentication -- all from a single declaration.
The Problem¶
Building IoT into a Django project today means writing hundreds of lines of boilerplate: MQTT client callbacks, custom models for each device type, manual topic routing, separate auth endpoints for brokers, and custom API views. None of it is reusable across projects.
The Solution¶
# devices.py
from django_devicehub import DeviceType, Reading, Command, reading_types
class WeatherStation(DeviceType):
temperature = Reading(type=reading_types.FLOAT, unit="C", range=(-40, 80))
humidity = Reading(type=reading_types.FLOAT, unit="%", range=(0, 100))
reboot = Command()
# models.py
from .devices import WeatherStation
WeatherStationDevice, WeatherStationReading, WeatherStationMessage = (
WeatherStation.create_models()
)
That's it. Run makemigrations, migrate, and you have:
| Generated automatically | What it does |
|---|---|
| Database tables | Device registry, time-series readings, raw message audit trail |
| MQTT topics | myproject/weatherstation/{device_id}/data, /status, /cmd |
| REST API | /api/devices/, /api/devices/{id}/readings/, /api/devices/{id}/provision/ |
| Django Admin | Full admin with filters, search, date hierarchy |
| Broker auth | HTTP endpoints for EMQX/Mosquitto device authentication |
| Signals | device_data_received, device_status_changed, etc. |
Features¶
- Declarative device types with
Reading,Command, andStateFielddescriptors - Concrete Django models via
create_models()+ standardmakemigrations - MQTT 5.0 via paho-mqtt (shared subscriptions, TLS, QoS)
- Pluggable storage -- Django ORM, TimescaleDB, InfluxDB 2.x
- Realtime -- Django Channels WebSocket + SSE +
iot.jsfrontend library - Device provisioning with credential management
- Management commands --
iot_listen,iot_simulate,iot_provision
Quick Install¶
Then follow the Quick Start guide.