Skip to main content

MQTT tools.

Project description

buildstatus coverage

MQTT Tools

MQTT tools in Python 3.7 and later.

Both the client and the broker implments MQTT version 5.0 using asyncio.

Client features:

  • Subscribe to and publish QoS level 0 topics.

  • Broker session resume (or clean start support) for less initial communication.

  • Topic aliases for smaller publish packets.

  • monitor, subscribe and publish command line commands.

Broker features:

  • Subscribe to and publish QoS level 0 topics.

  • Session resume (or clean start support) for less initial communication. Session state storage in RAM.

  • broker command line command.

Limitations:

There are lots of limitations in both the client and the broker. Here are a few of them:

  • QoS level 1 and 2 messages are not supprted. A session state storage is required to do so, both in the client and the broker.

  • Authentication is not supported.

MQTT version 5.0 specification: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html

Project homepage: https://github.com/eerimoq/mqttools

Documentation: https://mqttools.readthedocs.org/en/latest

Installation

pip install mqttools

Examples

There are plenty of examples in the examples folder.

Command line

Subscribe

Connect to given MQTT broker and subscribe to a topic. All received messages are printed to standard output.

$ mqttools subscribe /test/#
Connecting to 'broker.hivemq.com:1883'.

Topic:   /test
Message: 11
Topic:   /test/mqttools/foo
Message: bar

Publish

Connect to given MQTT broker and publish a message to a topic.

$ mqttools publish /test/mqttools/foo bar
Connecting to 'broker.hivemq.com:1883'.

Published 1 message(s) in 0 seconds from 1 concurrent task(s).

Publish multiple messages as quickly as possible with --count to benchmark the client and the broker.

$ mqttools publish --count 100 /test/mqttools/foo
Connecting to 'broker.hivemq.com:1883'.

Published 100 message(s) in 0.39 seconds from 10 concurrent task(s).

Monitor

Connect to given MQTT broker and monitor given topics in a text based user interface.

$ mqttools monitor /test/#
https://github.com/eerimoq/mqttools/raw/master/docs/monitor.png

The menu at the bottom of the monitor shows the available commands.

  • Quit: Quit the monitor. Ctrl-C can be used as well.

  • Play/Pause: Toggle between playing and paused (or running and freezed).

Broker

Start a broker to serve clients.

$ mqttools broker
Starting a broker at 'localhost:1883'.

Scripting

Subscribe

An example connecting to an MQTT broker, subscribing to the topic /test/#, and printing all published messaged.

import asyncio
import mqttools

async def subscriber():
    client = mqttools.Client('broker.hivemq.com', 1883)

    await client.start()
    await client.subscribe('/test/#')

    while True:
        topic, message = await client.messages.get()

        if topic is None:
            print('Broker connection lost!')
            break

        print(f'Topic:   {topic}')
        print(f'Message: {message}')

asyncio.run(subscriber())

Publish

An example connecting to an MQTT broker and publishing the message bar to the topic /test/mqttools/foo.

import asyncio
import mqttools

async def publisher():
    client = mqttools.Client('broker.hivemq.com', 1883)

    await client.start()
    client.publish('/test/mqttools/foo', b'bar')
    await client.stop()

asyncio.run(publisher())

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

mqttools-0.21.1.tar.gz (25.7 kB view details)

Uploaded Source

Built Distribution

mqttools-0.21.1-py2.py3-none-any.whl (23.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file mqttools-0.21.1.tar.gz.

File metadata

  • Download URL: mqttools-0.21.1.tar.gz
  • Upload date:
  • Size: 25.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

File hashes

Hashes for mqttools-0.21.1.tar.gz
Algorithm Hash digest
SHA256 8eb18ada420ad6e874a4cc875723db42e60bc9acd2ef025600966a6393887fe0
MD5 c72450367517fd467710ecf0ed93c424
BLAKE2b-256 0a35a8b29a8c4da394c1d07822b4c2c684eb2c34c21020393b5206a9bf606a11

See more details on using hashes here.

Provenance

File details

Details for the file mqttools-0.21.1-py2.py3-none-any.whl.

File metadata

  • Download URL: mqttools-0.21.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 23.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.18.4 setuptools/39.0.1 requests-toolbelt/0.9.1 tqdm/4.32.1 CPython/3.6.8

File hashes

Hashes for mqttools-0.21.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c0b2d4d79b4e7e28fb648fbb4a1ff16c9a4e7b8df4521b37a21a7918528ea282
MD5 8600b0f3ca0607b25f08370171a9262b
BLAKE2b-256 02aa98968c69c37502a646fee23831fd1ed2cf08106880094a63618146d86bf3

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page