{"id":1507,"library":"huey","title":"Huey Task Queue","description":"Huey is a lightweight, redis-backed task queue for Python applications. It supports thread, process, or greenlet workers, scheduling, retries, and result storage. The current version is 2.6.0, and it maintains an active release cadence with regular updates and compatibility fixes.","status":"active","version":"2.6.0","language":"en","source_language":"en","source_url":"https://github.com/coleifer/huey","tags":["task-queue","async","background-tasks","redis","scheduling"],"install":[{"cmd":"pip install huey","lang":"bash","label":"Install core Huey"},{"cmd":"pip install huey[redis]","lang":"bash","label":"Install Huey with Redis backend"}],"dependencies":[{"reason":"Required for the RedisHuey backend, which is the most common and recommended storage for production.","package":"redis","optional":true},{"reason":"Required if using 'greenlet' workers for concurrent task execution.","package":"gevent","optional":true}],"imports":[{"symbol":"Huey","correct":"from huey import Huey"},{"note":"RedisHuey is now a top-level import as of Huey 2.x, simplifying common usage.","wrong":"from huey.contrib.redis import RedisHuey","symbol":"RedisHuey","correct":"from huey import RedisHuey"},{"symbol":"crontab","correct":"from huey import crontab"}],"quickstart":{"code":"import os\nfrom huey import RedisHuey, crontab\n\n# Configure Huey with Redis, using an environment variable for host\nREDIS_HOST = os.environ.get('REDIS_HOST', 'localhost')\nhuey = RedisHuey(host=REDIS_HOST)\n\n# Define a simple task\n@huey.task()\ndef add_numbers(a, b):\n    print(f\"Adding {a} and {b}...\")\n    return a + b\n\n# Define a periodic task (runs every minute)\n@huey.periodic_task(crontab(minute='*/1'))\ndef say_hello_every_minute():\n    print(\"Hello from a periodic task!\")\n\nif __name__ == '__main__':\n    # Enqueue tasks\n    print(\"Enqueuing tasks...\")\n    result1 = add_numbers(10, 20)\n    result2 = add_numbers.schedule(args=(5, 5), delay=10)\n\n    print(f\"Task 1 enqueued. Result ID: {result1.id}\")\n    print(f\"Task 2 scheduled. Result ID: {result2.id}\")\n\n    # To run the consumer in a separate terminal:\n    # huey_consumer.py my_app.huey\n    # (assuming this code is in a file named my_app.py)\n\n    # To get a result (blocking):\n    # print(f\"Result of task 1: {result1.get(blocking=True, timeout=5)}\")\n","lang":"python","description":"This quickstart demonstrates how to set up Huey with a Redis backend, define a basic task, and a periodic task. It also shows how to enqueue tasks and retrieve their results. Remember to run a consumer process separately using `huey_consumer.py` to process tasks."},"warnings":[{"fix":"Be mindful of the operations performed within `SIGNAL_ENQUEUED` handlers. Avoid long-running, blocking, or resource-intensive tasks, as they will degrade the performance of your main application.","message":"The `SIGNAL_ENQUEUED` signal, introduced in 2.5.3, runs in the *calling process* (i.e., your main application), not the separate consumer process. Operations within this signal handler directly impact your application's request/response cycle.","severity":"gotcha","affected_versions":"2.5.3+"},{"fix":"Ensure `gevent.monkey.patch_all()` is executed at the very beginning of your application's entry point if you intend to use `greenlet` workers. Also, ensure `gevent` is installed (`pip install huey[gevent]`).","message":"When using `greenlet` workers, `huey` expects `gevent.monkey.patch_all()` to have been called *before* the `Huey` instance is created. Failure to do so (or a missing `gevent` dependency) will result in a warning and potential concurrency issues or unexpected behavior.","severity":"gotcha","affected_versions":"2.5.0+ (when warning was explicitly added)"},{"fix":"To ensure full compatibility with Python 3.12+ and 3.14+, upgrade Huey to at least version 2.5.4.","message":"Older Huey versions may have compatibility issues with newer Python releases. Specifically, versions `<2.5.1` may fail on Python 3.12+ due to `datetime.utcnow()` deprecation, and versions `<2.5.4` may have issues with multiprocessing start methods on Python 3.14+.","severity":"gotcha","affected_versions":"<2.5.4"},{"fix":"If using `redis-py` 4.0.0 or newer, upgrade Huey to at least 2.4.3. Alternatively, for older Huey versions, pin your `redis-py` dependency to `<4.0.0` (e.g., `redis-py<4.0.0`).","message":"Huey versions older than 2.4.3 are not compatible with `redis-py` 4.0.0+ due to significant API changes in `redis-py`. Attempting to use older Huey versions with `redis-py>=4.0.0` will result in runtime errors.","severity":"breaking","affected_versions":"<2.4.3"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}