Skip to main content

Declarative IoT device management for Django

Project description

Django DeviceHub

Declarative IoT device management for Django. Define device types with Python classes, get auto-generated models, REST API, admin, MQTT integration, and realtime updates.

PyPI version Python versions Django versions Tests License

Documentation | PyPI | Source

Quick Example

# devices.py - declare your device types
from django_devicehub import DeviceType, Reading, Command, reading_types

class WeatherStation(DeviceType):
    class Meta:
        protocol = "mqtt"
        heartbeat_interval = 300

    temperature = Reading(type=reading_types.FLOAT, unit="C", range=(-40, 80))
    humidity = Reading(type=reading_types.FLOAT, unit="%", range=(0, 100))
    rainfall = Reading(type=reading_types.FLOAT, unit="mm")

    reboot = Command()
    set_interval = Command(payload={"interval": int})
# models.py - one line generates 3 concrete Django models
from .devices import WeatherStation

WeatherStationDevice, WeatherStationReading, WeatherStationMessage = (
    WeatherStation.create_models()
)
python manage.py makemigrations    # generates migrations
python manage.py migrate           # creates tables
python manage.py iot_listen        # starts MQTT listener
python manage.py iot_simulate weatherstation --realistic  # simulate devices

Features

  • Declarative device types -- define readings, commands, and state fields as Python classes
  • Concrete model generation -- create_models() produces real Django models with makemigrations
  • MQTT 5.0 broker -- paho-mqtt with shared subscriptions, TLS, EMQX/Mosquitto compatible
  • Auto-generated REST API -- DRF viewsets with device CRUD, readings, and provisioning
  • Auto-generated admin -- Django admin registered automatically
  • Broker authentication -- HTTP auth/ACL endpoints for EMQX and Mosquitto
  • Device provisioning -- credential generation, bulk provisioning, API key management
  • Realtime updates -- Django Channels WebSocket + SSE fallback + iot.js frontend library
  • Pluggable storage -- Django ORM (default), TimescaleDB, InfluxDB 2.x
  • Django signals -- device_data_received, device_status_changed, device_provisioned, etc.
  • Management commands -- iot_listen, iot_simulate, iot_provision

Installation

pip install django-devicehub              # core
pip install django-devicehub[mqtt]        # + MQTT support
pip install django-devicehub[drf]         # + REST API
pip install django-devicehub[channels]    # + WebSocket realtime
pip install django-devicehub[all]         # everything

Add to INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    "django_devicehub",
    "myapp",
]

Configure the broker:

DJANGO_DEVICEHUB = {
    "BROKERS": {
        "default": {
            "ENGINE": "django_devicehub.brokers.mqtt.MQTTBroker",
            "HOST": "localhost",
            "PORT": 1883,
        }
    },
    "TOPIC_PREFIX": "myproject",
}

Documentation

Full documentation at altius-academy-snc.github.io/django-devicehub.

License

MIT -- see LICENSE.

Project details


Download files

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

Source Distribution

django_devicehub-0.2.1.tar.gz (52.9 kB view details)

Uploaded Source

Built Distribution

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

django_devicehub-0.2.1-py3-none-any.whl (51.9 kB view details)

Uploaded Python 3

File details

Details for the file django_devicehub-0.2.1.tar.gz.

File metadata

  • Download URL: django_devicehub-0.2.1.tar.gz
  • Upload date:
  • Size: 52.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for django_devicehub-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c78b3b924993f292551721f363c15a120f81e44273602f0eb170672664cc146a
MD5 0134f53bb57d2cbfeffcfebdd0d7e6ea
BLAKE2b-256 aa6d799b26654e946ef9afe428a351382183029b69114d891eb7cd31eac6e6db

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_devicehub-0.2.1.tar.gz:

Publisher: publish.yml on Altius-Academy-SNC/django-devicehub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_devicehub-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_devicehub-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a8b8a6ce11cbe4fcceed7eb0719169b51d762f855499215885b2888c420e9de3
MD5 82cb9a18df3690673ae10eb906327eab
BLAKE2b-256 fd99955e6f2215646a815b20b3e1137f7bf0ba45af6a3d9e562b4191b443217c

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_devicehub-0.2.1-py3-none-any.whl:

Publisher: publish.yml on Altius-Academy-SNC/django-devicehub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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