Skip to main content

An asynchronous RabbitMQ client for Python

Project description

Fast Rabbit Logo

Fast Rabbit: Asynchronous RabbitMQ Client for Python

GitHub release (latest by date including pre-releases) GitHub last commit GitHub open issues License

Fast Rabbit is an advanced, asynchronous RabbitMQ client designed to simplify the integration and management of RabbitMQ interactions within your Python applications. Leveraging the power of asyncio and aio_pika, Fast Rabbit provides a robust framework for message publishing and consuming, with an emphasis on simplicity, efficiency, and reliability.

Features

  • Asynchronous API: Built on top of asyncio, allowing for non-blocking message operations.
  • Easy Consumer Registration: Utilize decorators to effortlessly register message consumer coroutines.
  • Automatic Connection Management: Handles connection and channel lifecycle, including reconnections.
  • Flexible Routing: Incorporate a router similar to FastAPI for organised message handling based on queue names.
  • Prefetch Control: Easily configure the prefetch count for consumers to optimize message throughput and consumer workload.
  • Message Prioritisation: Supports prioritising messages to ensure that critical messages are processed before others, enhancing the responsiveness and efficiency of applications.
  • Custom Error Handling: Offers sophisticated error handling capabilities, including automatic retries with exponential backoff and dead-letter routing for messages that fail processing.

Installation

Install Fast Rabbit using pip:

pip install fast_rabbit

Quick Start

Publishing Messages

import asyncio
from fast_rabbit import FastRabbitEngine


RABBIT_MQ_URL = "amqp://user:password@localhost"
fast_rabbit = FastRabbitEngine(RABBIT_MQ_URL)

async def run_producer():
    for i in range(10):
        await fast_rabbit.publish("test_queue", f"Message {i}")
        print(f"Published message {i}")


if __name__ == "__main__":
    asyncio.run(run_producer())

Consuming Messages

Define your message handlers and register them as consumers for specific queues:

import asyncio
from fast_rabbit import FastRabbitEngine


RABBIT_MQ_URL = "amqp://user:password@localhost"
fast_rabbit = FastRabbitEngine(RABBIT_MQ_URL)

@fast_rabbit.subscribe("test_queue")
async def test_consumer(message: str):
    print(f"Received message: {message}")


if __name__ == "__main__":
    asyncio.run(fast_rabbit.run())

Example Upgrade

In this example, we showcase how message prioritisation, prefetch count, and Pydantic modelling can streamline message handling in Fast Rabbit. Prioritisation ensures urgent messages are processed first, enhancing system responsiveness. The prefetch count optimises workload by controlling how many messages are processed concurrently. Pydantic models validate and structure message data, improving code quality and maintainability. Together, these features form a robust framework for efficient, reliable messaging tailored to specific application needs.

Publish Message

import asyncio
from pydantic import BaseModel
from fast_rabbit import FastRabbitEngine

class Message(BaseModel):
    name: str
    price: int
    is_offer: Optional[bool] = None

async def run_producer():
    fast_rabbit = FastRabbitEngine(amqp_url="amqp://user:password@localhost")
    
    high_priority_message = Message(name="Urgent", price=100, is_offer=True)
    low_priority_message = Message(name="Regular", price=50, is_offer=False)
    
    # Publish a high priority message
    await fast_rabbit.publish("test_queue", high_priority_message, priority=5)
    print("Published high priority message")
    
    # Publish a low priority message
    await fast_rabbit.publish("test_queue", low_priority_message, priority=1)
    print("Published low priority message")

if __name__ == "__main__":
    asyncio.run(run_producer())

Consuming Messages

import asyncio
from pydantic import BaseModel
from fast_rabbit import FastRabbitEngine

class Message(BaseModel):
    name: str
    price: int
    is_offer: Optional[bool] = None

fast_rabbit = FastRabbitEngine(amqp_url="amqp://user:password@localhost")

@fast_rabbit.subscribe("test_queue", prefetch_count=10)
async def test_consumer(message: Message):
    print(f"Message name: {message.name}")
    print(f"Message price: {message.price}")
    if message.is_offer:
        print("Message is an offer")

if __name__ == "__main__":
    asyncio.run(fast_rabbit.run())

Documentation

For more detailed documentation, including API reference and advanced usage, please refer to the Fast Rabbit Documentation.

Contributing

Contributions are welcome! Please read our Contributing Guide for details on how to submit pull requests, report issues, and suggest improvements.

License

Fast Rabbit is released under the MIT License. See the LICENSE file for more details.


Fast Rabbit aims to provide a high-quality, easy-to-use asynchronous RabbitMQ client for the Python community. Whether you're building microservices, distributed systems, or just need a reliable way to handle message queues, Fast Rabbit is designed to meet your needs with minimal overhead and maximum efficiency.

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

fast_rabbit-0.1.18.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

fast_rabbit-0.1.18-py3-none-any.whl (18.2 kB view details)

Uploaded Python 3

File details

Details for the file fast_rabbit-0.1.18.tar.gz.

File metadata

  • Download URL: fast_rabbit-0.1.18.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.13

File hashes

Hashes for fast_rabbit-0.1.18.tar.gz
Algorithm Hash digest
SHA256 3c4ff1bcf0c3b3fe4684456b3213c5e5cffa2286e72aae946431c51714548be9
MD5 ab7d2f120a29ce33d8fea500f23ec412
BLAKE2b-256 a2299c6549751c59b1ee6757663d7b5e0d93ff459d995d1921d3b40c193d5d9a

See more details on using hashes here.

File details

Details for the file fast_rabbit-0.1.18-py3-none-any.whl.

File metadata

  • Download URL: fast_rabbit-0.1.18-py3-none-any.whl
  • Upload date:
  • Size: 18.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.13

File hashes

Hashes for fast_rabbit-0.1.18-py3-none-any.whl
Algorithm Hash digest
SHA256 f5441f83398d9a5338f50dae19f0cc012760f8e67fb38188f84d5af34a0667ad
MD5 b445afc3d79d9742ba834a76704d5da0
BLAKE2b-256 26edfb65748ea7d4137f27581359a0de96623d89e16a3d4d32961d88b40e49b2

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page