a lightweight alternative.
huey is:
a task queue (2019-04-01: version 2.0 released)
written in python (2.7+, 3.4+)
clean and simple API
redis, sqlite, or in-memory storage
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
task pipelines and chains
At a glance
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:
>>> 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:
>>> 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 or take a look at the example code.
Running the consumer
Run the consumer with four worker processes:
$ huey_consumer.py my_app.huey -k process -w 4
To run the consumer with a single worker thread (default):
$ 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:
$ 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 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
Project page
See source code and issue tracker on Github.
Huey is named in honor of my cat:
Metadata
Release files for huey 2.4.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| huey-2.4.1.tar.gz | 627.8 kB | Without provenance | Details for huey-2.4.1.tar.gz |
Release files / huey-2.4.1.tar.gz
| Download URL | huey-2.4.1.tar.gz |
|---|---|
| Size | 627.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd55e90746cec16e7a61d6dc60d4591c74cba59000dca96c387a4d4eee1395f6
|
|
BLAKE2b-256 checksum How to use checksums |
1f94d53e3ac7c380608e5a6a35585e71a5b3b4286ced50be6f1f7664f3b725a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
Python-urllib/3.7
|
Security for huey 2.4.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.