
Security News
Meet Socket at Black Hat and DEF CON 2025 in Las Vegas
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
.. image:: https://img.shields.io/pypi/l/Torrelque.svg :target: https://spdx.org/licenses/LGPL-3.0-only.html :alt: PyPI - License .. image:: https://heptapod.host/saajns/torrelque/badges/branch/default/pipeline.svg :target: https://heptapod.host/saajns/torrelque/-/commits/branch/default :alt: Pipeline status .. image:: https://heptapod.host/saajns/torrelque/badges/branch/default/coverage.svg :target: https://saajns.heptapod.io/torrelque/htmlcov/?badge=coverage :alt: Test code coverage .. image:: https://badge.fury.io/py/Torrelque.svg :target: https://pypi.python.org/pypi/Torrelque :alt: PyPI .. image:: https://img.shields.io/gitlab/pipeline-status/saajns%2Ftorrelque ?gitlab_url=https%3A%2F%2Fheptapod.host&branch=branch%2Fdefault&label=documentation :target: https://saajns.heptapod.io/torrelque/ :alt: RTFM
Torrelque
Torrelque is a Python package that provides minimal asynchronous reliable distributed Redis-backed (or a protocol-compatible alternative) work queues. It is built:
Supported Redis server implementations: Redis, KeyDB, Valkey.
::
pip install Torrelque
Producer:
.. sourcecode:: python
import redis.asyncio import torrelque
client = redis.asyncio.Redis() queue = torrelque.Torrelque(client, queue='email') queue.schedule_sweep() # to make due requeued tasks available again
task_data = {'addr': 'joe@doe.com', 'subj': 'hello', 'body': '...'} task_id = await queue.enqueue(task_data) print('Email task enqueued', task_id)
Consumer:
.. sourcecode:: python
import redis.asyncio import torrelque
client = redis.asyncio.Redis() queue = torrelque.Torrelque(client, queue='email')
while True: task_id, task_data = await queue.dequeue() try: await some_email_client.send(**task_data) except Exception: print('Email sending error, retrying in 30s', task_id) await queue.requeue(task_id, delay=30) else: print('Email sent', task_id) await queue.release(task_id)
Producer-consumer <e1_>
_. Infinite producing and consuming loops.Batch processing <e2_>
_. Finite number of tasks, consumers stop with a
poison pill, bulk enqueue. This example can be used as a synthetic benchmark.
Because there's no IO-bound workload, it'll be CPU-bound which isn't normal
mode of operation for an asynchronous application. But it can be used to
compare between CPython, PyPy and concurrency parameters.Web application background task <e3_>
_. This tornado application allows
to start a task and push server-sent events (SSE) to UI about its status. UI
starts a task and waits for it to complete. When a task fails it's re-queued
with exponential back-off... _e1: https://heptapod.host/saajns/torrelque/blob/branch/default/example/producer_consumer.py .. _e2: https://heptapod.host/saajns/torrelque/blob/branch/default/example/batch_processing.py .. _e3: https://heptapod.host/saajns/torrelque/blob/branch/default/example/wait_until_complete.py
FAQs
Asynchronous Redis-backed reliable queue package
We found that Torrelque demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Meet Socket at Black Hat & DEF CON 2025 for 1:1s, insider security talks at Allegiant Stadium, and a private dinner with top minds in software supply chain security.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.