Asynchronous framework for working with RabbitMQ
Project description
aiocarrot
aiocarrot is a fully asynchronous framework for working with the RabbitMQ message broker
Source Code: https://github.com/d3nbr0/aiocarrot
The key features are:
- Completely asynchronous - aiocarrot has the aiopika library running under the hood
- Fast to code - the framework allows you to reduce the amount of code in your project, as well as speed up its development
- Fields validation - aiocarrot supports field validation using pydantic
Requirements
The following dependencies are required for aiocarrot to work:
- aio-pika for working with RabbitMQ
- pydantic for fields validation
- ujson for sending and receiving messages
- loguru for logging :)
Installation
Create and activate virtual environment and then install aiocarrot:
pip install aiocarrot
Example
Create a file main.py
with:
from aiocarrot import Carrot, Consumer
import asyncio
consumer = Consumer()
@consumer.message(name='multiply')
async def multiply(first_number: int, second_number: int) -> None:
print('Result is:', first_number * second_number)
async def main() -> None:
carrot = Carrot(url='amqp://guest:guest@127.0.0.1/', queue_name='sample')
carrot.setup_consumer(consumer)
await carrot.run()
if __name__ == '__main__':
asyncio.run(main())
Then run it with:
python main.py
Now you have created a consumer with the ability to receive a "multiply" task
Produce message
If you want to send a message, use this:
from aiocarrot import Carrot
import asyncio
async def main() -> None:
carrot = Carrot(url='amqp://guest:guest@127.0.0.1:5672/', queue_name='sample')
await carrot.send('multiply', first_number=10, second_number=20)
if __name__ == '__main__':
asyncio.run(main())
You can find more examples here
It's very simple to use. Enjoy!
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
Built Distribution
File details
Details for the file aiocarrot-1.0.2.tar.gz
.
File metadata
- Download URL: aiocarrot-1.0.2.tar.gz
- Upload date:
- Size: 7.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9a1ac17860fce86654d8c03561ef736c780a0f333205e227a27d034b14571132 |
|
MD5 | 8db46d6b43d9e9c2edc882621ebdd7d6 |
|
BLAKE2b-256 | 58f6285abd2faf91995017cac79c8cc66c6d5f807e330e8912e51257cf183cdd |
File details
Details for the file aiocarrot-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: aiocarrot-1.0.2-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d73ffebcc533077b366a2c91fd06224d2749bbce497393ef3f5b62e7d805021e |
|
MD5 | 3769400302e1f3b24924c2f5ba80fc03 |
|
BLAKE2b-256 | 3fdc9fcb2bd74299ba1c7a449473b7aa0276f7141b4bb4c414ba5585124dc080 |