Skip to main content

No project description provided

Project description

README.md

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, properties: dict):
    print(f"Message received: {message.payload.decode()} on topic {message.topic}")

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

    async with client:  # Connect and automatically handle subscriptions
        await client.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, properties: dict):
    # Simulate getting a temperature reading
    return 25  # Return the temperature

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

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

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.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

fastmqtt-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastmqtt-0.1.0.tar.gz
  • Upload date:
  • Size: 7.7 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.0.tar.gz
Algorithm Hash digest
SHA256 8b2fa2ad00580a6bbd04b40ace96eaf9cb7e65f5fc8a650786dd2bbcf9504a43
MD5 81599d7a684659f90b598ba9ea6d2707
BLAKE2b-256 903d1853e6a0bd3bf2158012883d05495d48bcfcf30cfe5a65b5bc7d84a17105

See more details on using hashes here.

File details

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

File metadata

  • Download URL: fastmqtt-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ff31e19ce396bbf599c1de6f392701bf72408454553f6cae82e6d779565edd9c
MD5 13298913244e194a4ad6f56b9d740f7f
BLAKE2b-256 d2105c63b172a8d1726fe8972565beecd76ea29276217278576fc4a9b953a6b7

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