Catalog PyPI
Back to packageRELEASE DETAILS

1.1.0

PyPI

aiocarrot

Asynchronous framework for working with RabbitMQ

Published5 Feb 2025
Direct dependencies7
Transitive dependenciesNot calculated

README

Version 1.1.0 documentation

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!

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Declared dependencies 7

Native requirements
7 direct targetsNot calculated transitive count
Package / targetRequirementRelationship
aio-pika
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
aio-pika<9.5,>=9.4.3runtime
croniter
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
croniter>=6.0.0runtime
loguru
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
loguru<0.8.0,>=0.7.2runtime
pydantic
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pydantic<3.0.0,>=2.9.2runtime
ujson
Environment
{
  "extras": "",
  "marker": null,
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
ujson>=5.10.0runtime
pytest-asyncio
Environment
{
  "extras": "",
  "marker": "extra == \"test\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pytest-asyncio~=0.24.0; extra == "test"runtime
pytest
Environment
{
  "extras": "",
  "marker": "extra == \"test\"",
  "requires_python": ">=3.10",
  "evaluation": "NOT_EVALUATED"
}
pytest~=8.3.3; extra == "test"runtime

Distribution files

2 collected
aiocarrot-1.1.0-py3-none-any.whl

bdist_wheel · 11.05 KB · Python py3

Source file
aiocarrot-1.1.0.tar.gz

sdist · 10.46 KB · Python source

Source file

Repository

PENDING
d3nbr0/aiocarrot

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 11:42 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package_version:630de6f4a4d2ace6ac790b27ffe1d19d1d8ffd9f75e56bb140cda70ebdddcbf7

Other collected versions

View all collected versions →