{"name":"RQ: Simple Job Queues for Python with Redis/Valkey","description":"RQ (Redis Queue) is a straightforward Python library designed for managing job queues and processing tasks in the background. It leverages Redis or Valkey for backend storage, offering a low barrier to entry while ensuring excellent scalability for applications of all sizes. Developers can easily integrate RQ into their web stacks to handle asynchronous operations efficiently.","github":"https://github.com/rq/rq","url":"https://osrepos.com/repo/rq-rq","source":"osrepos.com","sourceDescription":"This repository profile is provided by osrepos.com, an open source repository discovery platform.","repositoryProfile":"https://osrepos.com/repo/rq-rq","generatedFor":"open source discovery and AI-assisted research","markdown":"https://osrepos.com/repo/rq-rq.md","json":"https://osrepos.com/repo/rq-rq.json","topics":["python","redis","job-queue","background-tasks","asynchronous","workers","task-queue","rq"],"keywords":["python","redis","job-queue","background-tasks","asynchronous","workers","task-queue","rq"],"stars":null,"summary":"RQ (Redis Queue) is a straightforward Python library designed for managing job queues and processing tasks in the background. It leverages Redis or Valkey for backend storage, offering a low barrier to entry while ensuring excellent scalability for applications of all sizes. Developers can easily integrate RQ into their web stacks to handle asynchronous operations efficiently.","content":"## Introduction\nRQ (Redis Queue) is a simple yet powerful Python library for managing job queues and processing tasks asynchronously in the background. Backed by Redis or Valkey, RQ is designed for ease of use, allowing developers to quickly integrate background processing into their applications. It offers a robust solution for projects ranging from small utilities to large-scale enterprise systems, providing excellent scalability and reliability.\n\n## Installation\nGetting started with RQ is straightforward. You can install the latest version using pip:\n\nconsole\n$ pip install rq\n\n\nRQ requires a running Redis or Valkey server (version 5 or higher for Redis, 7.2 or higher for Valkey).\n\n## Examples\n\n### Basic Job Enqueueing\nTo enqueue a job, first define your function, then create an RQ queue and add the function call to it:\n\npython\nimport requests\nfrom redis import Redis\nfrom rq import Queue\n\ndef count_words_at_url(url):\n    \"\"\"Just an example function that's called async.\"\"\"\n    resp = requests.get(url)\n    return len(resp.text.split())\n\n# Create an RQ queue\nqueue = Queue(connection=Redis())\n\n# Enqueue the function call\njob = queue.enqueue(count_words_at_url, 'https://stamps.id')\nprint(f\"Job ID: {job.id}\")\n\n\n### Job Prioritization\nRQ allows you to prioritize jobs in two ways:\n\n1.  **Enqueue at the front:**\n    python\n    job = queue.enqueue(count_words_at_url, 'https://stamps.id', at_front=True)\n    \n2.  **Use multiple queues:** Define separate queues for different priorities and start workers with a prioritized list.\n    python\n    from rq import Queue\n    high_priority_queue = Queue('high', connection=Redis())\n    low_priority_queue = Queue('low', connection=Redis())\n\n    high_priority_queue.enqueue(urgent_task)\n    low_priority_queue.enqueue(non_urgent_task)\n    \n    Then, start a worker:\n    console\n    $ rq worker high low\n    \n\n### Scheduling Jobs\nSchedule jobs to run at a specific time or after a delay:\n\npython\nfrom datetime import datetime, timedelta\n# Schedule job to run at 9:15, October 10th\njob = queue.enqueue_at(datetime(2019, 10, 10, 9, 15), say_hello)\n\n# Schedule job to run in 10 seconds\njob = queue.enqueue_in(timedelta(seconds=10), say_hello)\n\n\n### Repeating Jobs\nExecute a job multiple times using the `Repeat` class:\n\npython\nfrom rq import Repeat\n\n# Repeat job 3 times after successful execution, with 30 second intervals\nqueue.enqueue(my_function, repeat=Repeat(times=3, interval=30))\n\n\n### Unique Jobs\nPrevent duplicate jobs from being enqueued:\n\npython\njob = queue.enqueue(send_email, user_id, job_id='welcome-42', unique=True)\n\n\n### Rate Limiting\nApply concurrency-based rate limits to jobs sharing a key:\n\npython\nfrom rq import RateLimit\n\nqueue.enqueue(generate_report, rate_limit=RateLimit(key='reports', concurrency=2))\n\n\n### Retrying Failed Jobs\nConfigure jobs to retry upon failure:\n\npython\nfrom rq import Retry\n\n# Retry up to 3 times, failed job will be requeued immediately\nqueue.enqueue(say_hello, retry=Retry(max=3))\n\n\n### Webhooks\nSend HTTP requests to a URL when a job finishes or fails:\n\npython\nfrom rq import Webhook\n\nqueue.enqueue(\n    say_hello,\n    webhooks=[\n        Webhook('https://example.com/finished', job_status='finished'),\n        Webhook('https://example.com/failed', job_status='failed', method='POST'),\n    ],\n)\n\n\n### Cron Job Scheduling\nRQ provides built-in functionality for interval-based and cron syntax scheduling. Define your jobs in a configuration file:\n\npython\n# cron_config.py\nfrom rq import cron\nfrom myapp import cleanup_temp_files, generate_analytics_report\n\ncron.register(\n    cleanup_temp_files,\n    queue_name='maintenance',\n    interval=1800  # 30 minutes in seconds\n)\n\ncron.register(\n    generate_analytics_report,\n    queue_name='reports',\n    cron='0 8 1 * *' # Monthly report on the first day of each month at 8:00 AM\n)\n\nThen, start the `rq cron` command:\nconsole\n$ rq cron cron_config.py\n\n\n### The Worker\nTo process enqueued jobs, start an RQ worker:\n\nconsole\n$ rq worker --with-scheduler\n\nFor production, you can use `rq worker-pool` to run multiple worker processes:\nconsole\n$ rq worker-pool -n 4\n\n\n## Why Use RQ?\nRQ stands out for its simplicity and Pythonic approach to background job processing. It offers a lightweight alternative to more complex systems, making it easy to get started while providing powerful features like job prioritization, scheduling, retries, and webhooks. Its reliance on Redis/Valkey ensures high performance and reliability, making it suitable for a wide range of asynchronous tasks, from sending emails to complex data processing.\n\n## Links\n*   **Official Documentation:** <a href=\"http://python-rq.org/\" target=\"_blank\" rel=\"noopener noreferrer\">python-rq.org</a>\n*   **GitHub Repository:** <a href=\"https://github.com/rq/rq\" target=\"_blank\" rel=\"noopener noreferrer\">github.com/rq/rq</a>","metrics":{"detailViews":0,"githubClicks":0},"dates":{"published":null,"modified":"2026-08-05T08:57:01.000Z"}}