huey

a little task queue

77 个版本
安装
pip install huey
poetry add huey
pipenv install huey
conda install huey
描述

.. image:: https://media.charlesleifer.com/blog/photos/huey3-logo.png

a lightweight alternative.

huey is:

  • a task queue
  • written in python
  • clean and simple API

huey has:

  • support for redis (or valkey/redict), sqlite, file-system, or in-memory storage
  • example code <https://github.com/coleifer/huey/tree/master/examples/>_.
  • django <https://huey.readthedocs.io/en/latest/django.html>_ integration (native or via django.tasks)
  • documentation <https://huey.readthedocs.io/>_.

huey supports:

  • multi-process, multi-thread or greenlet task execution models
  • schedule tasks to execute at a given time, or after a given delay
  • schedule recurring tasks, like a crontab
  • automatically retry tasks that fail
  • task prioritization
  • task result storage
  • task expiration
  • task locking, rate-limits and timeouts
  • task pipelines and chains
  • groups (fan-out), chords (map / reduce)

.. image:: http://i.imgur.com/2EpRs.jpg

At a glance

.. code-block:: python

from huey import RedisHuey, crontab

huey = RedisHuey('my-app', host='redis.myapp.com')

@huey.task()
def add_numbers(a, b):
    return a + b

@huey.task(retries=2, retry_delay=60)
def flaky_task(url):
    # This task might fail, in which case it will be retried up to 2 times
    # with a delay of 60s between retries.
    return this_might_fail(url)

@huey.periodic_task(crontab(minute='0', hour='3'))
def nightly_backup():
    sync_all_data()

Calling a task-decorated function will enqueue the function call for execution by the consumer. A special result handle is returned immediately, which can be used to fetch the result once the task is finished:

.. code-block:: pycon

>>> from demo import add_numbers
>>> res = add_numbers(1, 2)
>>> res
<Result: task 6b6f36fc-da0d-4069-b46c-c0d4ccff1df6>

>>> res()
3

Tasks can be scheduled to run in the future:

.. code-block:: pycon

>>> res = add_numbers.schedule((2, 3), delay=10)  # Will be run in ~10s.
>>> res(blocking=True)  # Will block until task finishes, in ~10s.
5

For much more, check out the guide <https://huey.readthedocs.io/en/latest/guide.html>_ or take a look at the example code <https://github.com/coleifer/huey/tree/master/examples/>_.

Running the consumer ^^^^^^^^^^^^^^^^^^^^

Run the consumer with four worker processes:

.. code-block:: console

$ huey_consumer.py my_app.huey -k process -w 4

To run the consumer with a single worker thread (default):

.. code-block:: console

$ huey_consumer.py my_app.huey

If your work-loads are mostly IO-bound, you can run the consumer with threads or greenlets instead. Because greenlets are so lightweight, you can run quite a few of them efficiently:

.. code-block:: console

$ huey_consumer.py my_app.huey -k greenlet -w 32

Storage

Huey's design and feature-set were informed by the capabilities of the Redis <https://redis.io>_ database. Redis is a fantastic fit for a lightweight task queueing library like Huey: it's self-contained, versatile, and can be a multi-purpose solution for other web-application tasks like caching, event publishing, analytics, rate-limiting, and more.

Although Huey was designed with Redis in mind, the storage system implements a simple API and many other tools could be used instead of Redis if that's your preference.

Huey comes with builtin support for Redis, Sqlite and in-memory storage.

Documentation

See Huey documentation <https://huey.readthedocs.io/>_.

Project page

See source code and issue tracker on Github <https://github.com/coleifer/huey/>_.

Huey is named in honor of my cat:

.. image:: http://m.charlesleifer.com/t/800x-/blog/photos/p1473037658.76.jpg?key=mD9_qMaKBAuGPi95KzXYqg

版本列表
3.0.3 2026-06-12
3.0.2 2026-06-11
3.0.1 2026-05-14
3.0.0 2026-04-14
2.6.0 2026-01-06
2.5.5 2025-12-05
2.5.4 2025-10-23
2.5.3 2025-03-19
2.5.2 2024-09-25
2.5.1 2024-06-07
2.5.0 2023-09-20
2.4.5 2023-02-09
2.4.4 2022-10-21
2.4.3 2021-12-28
2.4.2 2021-11-28
2.4.1 2021-09-16
2.4.0 2021-08-10
2.3.2 2021-04-20
2.3.1 2021-03-04
2.3.0 2020-08-10
2.2.0 2020-02-23
2.1.3 2019-10-16
2.1.2 2019-09-04
2.1.1 2019-08-07
2.1.0 2019-06-06
2.0.1 2019-04-03
2.0.0 2019-04-01
1.11.0 2019-02-16
1.10.5 2018-12-19
1.10.4 2018-11-14
1.10.3 2018-10-09
1.10.2 2018-08-14
1.10.1 2018-07-24
1.10.0 2018-05-30
1.9.1 2018-04-04
1.9.0 2018-03-12
1.8.0 2018-03-09
1.7.0 2018-02-07
1.6.1 2018-01-25
1.6.0 2018-01-12
1.5.6 2017-12-10
1.5.5 2017-11-02
1.5.4 2017-10-23
1.5.3 2017-10-22
1.5.2 2017-10-16
1.5.1 2017-10-08
1.5.0 2017-10-05
1.4.1 2017-09-08
1.4.0 2017-08-01
1.3.1 2017-05-09
1.3.0 2017-04-13
1.2.3 2017-02-17
1.2.2 2016-10-17
1.2.1 2016-10-02
1.2.0 2016-07-21
1.1.2 2016-05-04
1.1.1 2016-03-10
1.1.0 2016-01-21
1.0.0 2016-01-06
0.4.9 2015-09-26
0.4.8 2015-05-11
0.4.7 2015-02-05
0.4.6 2015-02-05
0.4.5 2015-02-05
0.4.3 2014-09-04
0.4.2 2014-03-13
0.4.1 2013-06-05
0.4.0 2013-05-09
0.3.2 2012-12-01
0.3.1 2012-11-28
0.3.0 2012-11-27
0.2.2 2012-08-21
0.2.1 2012-04-06
0.2.0 2012-01-28
0.1.1 2012-01-07
0.1.0 2012-01-04