Skip to main content

aiocarrot

aiocarrot is a fully asynchronous framework for working with the RabbitMQ message broker

Tests Version

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
  • Scheduler - describe the task launch period in the cron format

Requirements

The following dependencies are required for aiocarrot to work:

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())

Scheduler

You can use the scheduler to run your tasks automatically.
You can schedule a task using the cron format. For example, to run a task once every 15 minutes: */15 * * * *

@consumer.message(name='example.scheduler', schedule='*/15 * * * *')
async def scheduler_message(value: Optional[int] = None) -> None:
    print('Your value is:', value or 0)

NOTE: The scheduler does not support working with arguments that do not have default values. If you want to schedule a message and it has arguments, make sure they all have a default value.

You can find more examples here

It's very simple to use. Enjoy!

Metadata

Release files for aiocarrot 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aiocarrot 1.1.0
File Size Uploaded Provenance
aiocarrot-1.1.0.tar.gz 10.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aiocarrot 1.1.0
File Interpreter ABI Platform
aiocarrot-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.0 kB

Release files / aiocarrot-1.1.0.tar.gz

Download URL aiocarrot-1.1.0.tar.gz
Size 10.7 kB
Tags Source
SHA-256 checksum
How to use checksums
5a0208ca2b26ba97509604ef23bbdfde75422cfc8b36c95f3527af9401ebdce6
BLAKE2b-256 checksum
How to use checksums
7a958ec3d9d16e04bb3a8e4c045efe21020543999b5b6371392310a3e41bece6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release files / aiocarrot-1.1.0-py3-none-any.whl

Download URL aiocarrot-1.1.0-py3-none-any.whl
Size 11.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a5276064a2e39a8986e3165230f648742c95b004e49ad22326d6dd96e1c3fe2e
BLAKE2b-256 checksum
How to use checksums
c4e4ff28773229388ec6745ffaac735d3242ed7637f0e031106aa47d8889ff60
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Security for aiocarrot 1.1.0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page