roq
Pythonic RPC over MQTT for aiomqtt
- 💡 Clean interface, RPC with just a decorator
- 💪 Robust multi-client implementation
- 🤝 Seamlessly integrates with aiomqtt
Quick start
Server Side: Expose a function over MQTT:
import roq
@roq.procedure("/your/topic/name")
def sum(a, b):
return a + b
Client Side: Call that function over MQTT:
import roq
async with client:
ret = await client["/your/topic/name"](1, 2)
installation
pip install roq
Usage
To create a roq-enabled aiomqtt.Client you can:
- Replace
aiomqtt.Clientwithroq.Clientin your code (full documentation here)
import roq
client = roq.Client(
... # Your usual MQTT client setup
)
async with client:
# Call RPCs, subscribe, handle messages, the usual stuff
await client["/your/topic/name"](some, argument, some=keyword)
await client.subscribe("/some/other/topic")
async for message in client.messages:
print("Received message on topic", message.topic)
- Wrap an existing
aiomqtt.Clientwithroq.Client(queue_typemust be an instance ofroq.ROQRouterQueue)
import roq
import aiomqtt
client = aiomqtt.Client(
... # Your usual MQTT client setup
queue_type=roq.ROQRouterQueue
)
async with roq.Client(client) as client:
# Same as above, subscribe, call, handle
Use the roq.procedure("/topic/name") decorator to bind a function to be called on /topic/name.
Use client["/topic/name"](your, arguments, oreven=keywoardargs) to call a function bound to /topic/name
Examples
server.py:
import roq
import asyncio
@roq.procedure("/rpc/sum")
def sum(a, b):
return a + b
async def main():
client = roq.Client("test.mosquitto.org")
async with client:
await client.subscribe("/some/other/topic")
async for message in client.messages:
print("Received message on topic", message.topic)
if __name__ == "__main__":
asyncio.run(main())
client.py:
import roq
import asyncio
async def main():
client = roq.Client("test.mosquitto.org")
async with client:
ret = await client["/rpc/sum"](1, 2)
print(f"Result from RPC: {ret}")
await client.publish("/some/other/topic", payload=b"Hello, World!")
if __name__ == "__main__":
asyncio.run(main())
Use a custom queue
You can use a custom queue extending roq.ROQRouterQueue
import roq
class YourQueue(roq.ROQRouterQueue)
def _put(self, item):
if self.handle_roq_message(item): return # handle roq messages
#your item logic here
super()._put(item)
def _get(self):
return super()._get()
License
This project is licensed under the Apache License 2.0. For more details, see the LICENSE file in the root directory of this project or check out the Apache License 2.0 here
Metadata
Release files for roq 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| roq-0.0.2.tar.gz | 8.0 kB | Without provenance | Details for roq-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| roq-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for roq-0.0.2-py3-none-any.whl |
Total release size: 17.0 kB
Release files / roq-0.0.2.tar.gz
| Download URL | roq-0.0.2.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
193a5bfb07e13e1e47a02a815fdfcb7be56442e47d51a1837511b9bc6d7ccdce
|
|
BLAKE2b-256 checksum How to use checksums |
3046560a8a38230a537e1d3ba2cc08f11f1500662afa8e461fba2a7238cf3932
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Release files / roq-0.0.2-py3-none-any.whl
| Download URL | roq-0.0.2-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa4c4b45882ede6864b786df5d569e5b61b6c2b8061e1e6a53b2ff7c08487e67
|
|
BLAKE2b-256 checksum How to use checksums |
57ca10a31891ddb434a185f60bb6d50072026628098729587d50be70615a378a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.12.2
|
Security for roq 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.