Skip to main content

a little task queue

Project description

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), postgres, sqlite, file-system, or in-memory storage

  • zero dependencies (redis-py required to use redis-like brokers, psycopg for postgres).

  • example code.

  • django integration (native or via django.tasks) with admin integration for visibility and management.

  • documentation.

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)

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

At a glance

from huey import RedisHuey, crontab

# Or PostgresHuey, SqliteHuey, FileHuey, etc...
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 my_app.huey -k process -w 4

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

$ huey_consumer 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 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, Postgres, Sqlite, File-system, and in-memory storage.

Frameworks

Huey provides Django integration either natively or via django.tasks. Huey also provides an optional admin integration for Django:

https://huey.readthedocs.io/en/latest/_images/django-admin.png

Huey also provides flask-peewee admin integration based on the same underlying stat-tracking system:

https://huey.readthedocs.io/en/latest/_images/flask-admin-panel.png

Other frameworks can use the stats extension to collect and display this information.

Documentation

See Huey documentation.

Project page

See source code and issue tracker on Github.

Huey is named in honor of my cat:

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

Project details


Release history Release notifications | RSS feed

This version

3.2.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

huey-3.2.1.tar.gz (601.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

huey-3.2.1-py3-none-any.whl (121.0 kB view details)

Uploaded Python 3

File details

Details for the file huey-3.2.1.tar.gz.

File metadata

  • Download URL: huey-3.2.1.tar.gz
  • Upload date:
  • Size: 601.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for huey-3.2.1.tar.gz
Algorithm Hash digest
SHA256 79cd63d117e5b8da2de58420dcde4e2d0f963e362d67a9b3872ce565eec5c3dc
MD5 6a5d3966c2b4ac6baabe7b56660f2a09
BLAKE2b-256 5559de9e22fa4be35ee03eff7be144a92c32c63c9a80e323a45f260089162b97

See more details on using hashes here.

File details

Details for the file huey-3.2.1-py3-none-any.whl.

File metadata

  • Download URL: huey-3.2.1-py3-none-any.whl
  • Upload date:
  • Size: 121.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for huey-3.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 da9e004b80941a718f33f9714697a67e6d5cf12e0707fc4f3dbb5d9c796e7224
MD5 e30c99466cbf296a830a16f10f460052
BLAKE2b-256 a49e7fe3bdca0b2749f4b80a50bf033e9f83db6310b75f93c7aa74543f667dbe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page