Skip to main content

Python package for setting up and retrieving data from Axis devices using MQTT

Project description

ax-devil banner

ax-devil-mqtt

Python package for easy configuration and consumption of an Axis devices analytics data over MQTT.

See also ax-devil-device-api and ax-devil-rtsp for related tools.


Install

pip install ax-devil-mqtt

Configure (optional)

Set environment variables to avoid repeating credentials and broker details:

  • AX_DEVIL_TARGET_ADDR – Device IP or hostname
  • AX_DEVIL_TARGET_USER – Device username
  • AX_DEVIL_TARGET_PASS – Device password
  • AX_DEVIL_MQTT_BROKER_ADDR – MQTT broker address
  • AX_DEVIL_MQTT_BROKER_PASS – MQTT broker password

CLI

Run ax-devil-mqtt --help or ax-devil-mqtt help <command> for full details. Common flows:

  • Discover analytics data sources:
ax-devil-mqtt list-sources \
  --device-ip <device-ip> \
  --device-username <username> \
  --device-password <password>
  • Monitor an analytics stream (use your IP instead of localhost for the broker):
ax-devil-mqtt monitor \
  --device-ip <device-ip> \
  --device-username <username> \
  --device-password <password> \
  --broker-address <broker-ip> \
  --broker-port 1883 \
  --stream "com.axis.analytics_scene_description.v0.beta#1" \
  --duration 3600       # 0 to run continuously
  • Subscribe to an existing MQTT topic without configuring the device:
ax-devil-mqtt subscribe \
  --broker-address <broker-ip> \
  --broker-port 1883 \
  --topic "some/topic"
  • Inspect or clean analytics publishers configured on the device:
ax-devil-mqtt list-publishers \
  --device-ip <device-ip> \
  --device-username <username> \
  --device-password <password>

ax-devil-mqtt clean \
  --device-ip <device-ip> \
  --device-username <username> \
  --device-password <password>
  • Open the device’s Analytics MQTT API UI in your browser:
ax-devil-mqtt open-api \
  --device-ip <device-ip> \
  --device-username <username> \
  --device-password <password>

Python API

import time
from ax_devil_mqtt import AxisAnalyticsMqttClient, RawMqttClient, MqttMessage
from ax_devil_device_api import DeviceConfig

# Subscribe to an existing topic
client = RawMqttClient(
    broker_host="192.168.1.100",
    broker_port=1883,
    topics=["some/topic"],
    message_callback=lambda message: print(message.payload),
    worker_threads=1,  # dispatch callbacks on a background thread
)
client.start()
time.sleep(5)
client.stop()

# Or configure the device to publish analytics and subscribe automatically
device_config = DeviceConfig.http(host="192.168.1.200", username="root", password="pass")

analytics_client = AxisAnalyticsMqttClient(
    broker_host="192.168.1.100",
    broker_port=1883,
    device_config=device_config,
    analytics_data_source_key="com.axis.analytics_scene_description.v0.beta#1",
    message_callback=lambda message: print(message.payload),
    worker_threads=1,
)
analytics_client.start()
time.sleep(5)
analytics_client.stop()

Development

python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"

pytest
mypy src tests

Disclaimer

This project is an independent, community-driven implementation and is not affiliated with or endorsed by Axis Communications AB. For official APIs and development resources, see the Axis Developer Community.

License

MIT License - see LICENSE for details.

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

ax_devil_mqtt-0.4.3.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

ax_devil_mqtt-0.4.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file ax_devil_mqtt-0.4.3.tar.gz.

File metadata

  • Download URL: ax_devil_mqtt-0.4.3.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for ax_devil_mqtt-0.4.3.tar.gz
Algorithm Hash digest
SHA256 ac3e30966893ec8ed7347108eb4498632a4f2a31ca3a1bbd177ecbc70be0e368
MD5 10b7324ab7fc6fd24e62aef8b6431d5f
BLAKE2b-256 4dec55499f64d050d48528ca701d644152cc969d96ccc5b8f185ebdbc2b04c6f

See more details on using hashes here.

File details

Details for the file ax_devil_mqtt-0.4.3-py3-none-any.whl.

File metadata

  • Download URL: ax_devil_mqtt-0.4.3-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for ax_devil_mqtt-0.4.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6963ca961c89d4dd87fc8c8e1f1913b99e6e0fef31c9e79a4efe0ab1252d06c3
MD5 1641fa2a5be486d4a5c02cfed48a9f83
BLAKE2b-256 0156be9030f9c1fd54c22ab0cf1d58e6c098fa7ec0eee9d3037a989bfa552e4a

See more details on using hashes here.

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