Skip to main content

RobustMQ Python SDK — mq9 AI-native async messaging

Project description

robustmq-python

Python SDK for RobustMQ — mq9 AI-native async messaging.

Install

pip install robustmq

Requires Python 3.10+. The only runtime dependency is nats-py.

Quick start

import asyncio
from robustmq.mq9 import Client, Message

async def main():
    async with Client(server="nats://localhost:4222") as client:
        # Create a private mailbox (TTL 1 hour)
        mailbox = await client.create(ttl=3600)
        print(f"Mailbox: {mailbox.mail_id}")

        # Send a message
        await client.send(mailbox.mail_id, {"task": "summarize", "doc": "abc"})

        # Receive messages
        async def handler(msg: Message) -> None:
            print(f"[{msg.priority}] {msg.payload}")
            await client.delete(msg.mail_id, msg.msg_id)

        sub = await client.subscribe(mailbox.mail_id, handler)
        await asyncio.sleep(5)
        await sub.unsubscribe()

asyncio.run(main())

Worker pool (competitive consumption)

async with Client() as client:
    # Multiple workers share a queue group — each message goes to exactly one worker
    async def worker(msg: Message) -> None:
        print(f"Worker got: {msg.payload}")

    await client.subscribe("task.queue", worker, queue_group="workers")
    await asyncio.Future()  # run forever

Public mailbox discovery

async with Client() as client:
    mailboxes = await client.list_public()
    for mb in mailboxes:
        print(mb.mail_id, mb.desc)

API reference

Client(server, *, max_reconnect_attempts, reconnect_time_wait, request_timeout, name)

Parameter Default Description
server nats://localhost:4222 NATS server URL
max_reconnect_attempts 10 Auto-reconnect attempts (-1 = unlimited)
reconnect_time_wait 2.0 Seconds between reconnect attempts
request_timeout 5.0 Request/reply timeout in seconds

Methods

Method Description
await client.connect() Connect to server
await client.close() Drain and disconnect
await client.create(ttl, *, public, name, desc) Create mailbox → Mailbox
await client.send(mail_id, payload, *, priority) Send message
await client.subscribe(mail_id, callback, *, priority, queue_group) Subscribe → Subscription
await client.list(mail_id) List messages → list[Message]
await client.delete(mail_id, msg_id) Delete message
await client.list_public() Discover public mailboxes → list[Mailbox]

Client is also an async context manager (async with Client(...) as client).

Running tests

cd python
pip install -e ".[dev]"
pytest

No live server required — all tests use mocks.

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

robustmq-1.0.0.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

robustmq-1.0.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file robustmq-1.0.0.tar.gz.

File metadata

  • Download URL: robustmq-1.0.0.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for robustmq-1.0.0.tar.gz
Algorithm Hash digest
SHA256 6e29cd37ba0eae23faa943f15407c86dbc3fdcea6e2ed10010b164d449e96914
MD5 a7b744f676254b20c510e844de02d2c2
BLAKE2b-256 19e66de1396d56465661205120504250013238a8724ec7f0649af6f4209a1853

See more details on using hashes here.

File details

Details for the file robustmq-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: robustmq-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for robustmq-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 73615777c8857004a49c80853415edde3f13cb92ce9f12210393701d4c73d8ca
MD5 573ac911287ac2fadcd61a288e6f6fee
BLAKE2b-256 7fb90dd15acb4a4c8c9023891f1ff0a12d76d612eb745f55f900661bbbe1c0b6

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