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 Python Django Tests License: MIT

Documentation

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.1.2.tar.gz (52.6 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.1.2-py3-none-any.whl (51.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_devicehub-0.1.2.tar.gz
  • Upload date:
  • Size: 52.6 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.1.2.tar.gz
Algorithm Hash digest
SHA256 bf359d9fc0aeef188e7cb0bd2f4c5eda49a8f8540036228416c9133c18a8449e
MD5 64b9fb2ba7199633c3fe7f629b398509
BLAKE2b-256 932e5440dea765b3b404f65bba17905a3da2bf3a0dbd0e8af49b713d7f51d98c

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_devicehub-0.1.2.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.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for django_devicehub-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5ad2bf3a98469981961be860991fbc2c3052562e55937cd4888023676da406a0
MD5 e6db376a59a0b684f50a31e70bd64608
BLAKE2b-256 26115615110faf8e775ff8152623e76af8ceacb5c651ba3f6323f79ca6dd772a

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_devicehub-0.1.2-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