Python client for ForestMQ
Project description
ForestMQ Python
Python client for ForestMQ
Install
pip install forestmq
Running ForestMQ
docker run -p 8005:8005 josefdigital/forestmq:0.6.2
Examples
Using the provider API
from forestmq import ForestMQ
def sync_example():
fmq = ForestMQ(domain="http://localhost:8005")
result = fmq.provider.send_msg_sync({
"name": "Sync message",
})
print(result)
sync_example() # {'queue_length': 38, 'message_size': 5120, 'message': {'name': 'Sync message'}}
Using the provider's async client
import asyncio
from forestmq import ForestMQ
async def async_example():
fmq = ForestMQ(domain="http://localhost:8005")
result = await fmq.provider.send_msg({
"name": "Async message!",
})
print(result)
asyncio.run(async_example()) # {'queue_length': 39, 'message_size': 5120, 'message': {'name': 'Async message!'}}
Using the consumer API
import asyncio
from forestmq import ForestMQ
def callback(message: dict) -> None:
print(f"Consumer message: {message['message']}")
if __name__ == "__main__":
fmq = ForestMQ(domain="http://localhost:8005", interval=1)
asyncio.run(fmq.consumer.poll_sync(callback))
Async consumer example
import asyncio
from forestmq import ForestMQ
async def callback(message: dict) -> None:
await asyncio.sleep(1)
print(f"Consumer message: {message['message']}")
if __name__ == "__main__":
fmq = ForestMQ(domain="http://localhost:8005", interval=1)
asyncio.run(fmq.consumer.poll(callback))
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
forestmq-0.2.1.tar.gz
(6.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file forestmq-0.2.1.tar.gz.
File metadata
- Download URL: forestmq-0.2.1.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
38dc7be3dbe0cb780a5d6d540c2a69137ab7b755f2e6a62249810100a1258d18
|
|
| MD5 |
b81980d16497143460d06f7d4498f551
|
|
| BLAKE2b-256 |
500b87caca72dc0c3f1dfa9d419f0fb038e9196deaaaefadf92e618cfed69d20
|
File details
Details for the file forestmq-0.2.1-py3-none-any.whl.
File metadata
- Download URL: forestmq-0.2.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
97e28a6faeb964a25f2cec02340f249419a36e43587968203f594b947b270a87
|
|
| MD5 |
e765936760d9553bfa641bb45319a717
|
|
| BLAKE2b-256 |
5f9fb997a567531fe29903183478c69499c5895ca329cec0494d2107809ae2b5
|