Skip to main content

No project description provided

Project description

FastMQTT

A performant, flexible, and user-friendly MQTT client library built on top of aiomqtt. FastMQTT simplifies message handling, advanced subscriptions, and convenient request-response patterns within the MQTT protocol.

Key Features

  • Efficient Message Handling: Streamlined asynchronous message processing.
  • Robust Router: Define topic-based message routing with QoS, no_local, retain options.
  • Subscription Management: Effortlessly manage subscriptions, including retained messages.
  • Request-Response Patterns: Convenient ResponseContext for request-response communication over MQTT.
  • Correlation Tracking: Automatic correlation ID generation to match responses with their requests.
  • aiomqtt Foundation: Built upon the reliable aiomqtt library for core MQTT functionality.

Installation

pip install fastmqtt

Basic Usage

import asyncio
from fastmqtt import FastMQTT, MQTTRouter

router = MQTTRouter()

@router.on_message("my/topic")  # Subscribe and handle incoming messages
async def message_handler(message: Message):
    print(f"Message received: {message.payload.decode()} on topic {message.topic}")

async def main():
    fastmqtt = FastMQTT("mqtt.example.com", routers=[router]) 

    async with fastmqtt:  # Connect and automatically handle subscriptions
        await fastmqtt.publish("my/topic", "Hello from FastMQTT!")
        await asyncio.sleep(5)  # Keep running for a bit 

if __name__ == "__main__":
    asyncio.run(main())

Request-Response Example

@router.on_message("temperature/request")
async def temp_request_handler(message: Message):
    # Simulate getting a temperature reading
    return 25  # Return the temperature

async def main():
    fastmqtt = FastMQTT("mqtt.example.com", routers=[router])

    async with fastmqtt:
        async with fastmqtt.response_context(f"temperature/response/{fastmqtt.identifier}") as ctx:
            response = await ctx.request("temperature/request")
            print(f"Temperature: {response.payload.decode()}") 

Passing data Example

import asyncio
from fastmqtt import FastMQTT, MQTTRouter

router = MQTTRouter()

@router.on_message("my/topic")  # Subscribe and handle incoming messages
async def message_handler(message: Message, properties: dict):
    print(f"Message received: {message.payload.decode()} on topic {message.topic}")

async def main():
    fastmqtt = FastMQTT("mqtt.example.com", routers=[router]) 

    async with fastmqtt:  # Connect and automatically handle subscriptions
        await fastmqtt.publish("my/topic", "Hello from FastMQTT!")
        await asyncio.sleep(5)  # Keep running for a bit 

if __name__ == "__main__":
    asyncio.run(main())

Contributions

We welcome contributions to improve FastMQTT! Please open issues for bug reports or feature suggestions, and fork the repository to submit pull requests.

Let me know if you'd like modifications or have specific aspects you want to emphasize in the README!

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

fastmqtt-0.1.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

fastmqtt-0.1.1-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

Details for the file fastmqtt-0.1.1.tar.gz.

File metadata

  • Download URL: fastmqtt-0.1.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for fastmqtt-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c97e4272bb1b26561f1501eba9260e8dbd25781ea1232fc189847bade24237fb
MD5 adc57f2d53e045827066a5dded618b05
BLAKE2b-256 fbe3f36a1578e0f9a2f9755987fa823edeaec26972339fd7999fea240c097222

See more details on using hashes here.

File details

Details for the file fastmqtt-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: fastmqtt-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for fastmqtt-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 929ca0bf06c73c82c0825d8239cc7998af95279fa35ef640cc698720417e4846
MD5 2cb45d2d5e396c759391ccc84b951bd8
BLAKE2b-256 40969c78f48de33d8126ed9961ac67764bf232c3a6142bfab193f26e6c8034fc

See more details on using hashes here.

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