Skip to main content

MQTT tools.

Project description

buildstatus coverage

MQTT Tools

Requires Python 3.7 or later!

Features:

  • asyncio MQTT client.

Examples

Command line

Subscribe

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

$ mqttools subscribe /test/#
Topic:   b'/test'
Message: b'11'

Topic:   b'/test/mqttools/foo'
Message: b'bar'

Publish

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

$ mqttools publish /test/mqttools/foo bar
Topic:   b'/test/mqttools/foo'
Message: b'bar'
QoS:     0

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('test.mosquitto.org', 1883, b'mqttools-subscribe')

    await client.start()
    await client.subscribe(b'/test/#', 0)

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

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

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('test.mosquitto.org', 1883, b'mqttools-publish')

    await client.start()
    await client.publish(b'/test/mqttools/foo', b'bar', 0)
    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.3.0.tar.gz (6.9 kB view hashes)

Uploaded Source

Built Distribution

mqttools-0.3.0-py2.py3-none-any.whl (6.4 kB view hashes)

Uploaded Python 2 Python 3

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