Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Simple offline task queues.

Project Description

Simple offline task queues. For Python.

“See you later, alligator.”


  • Python 2.6+ or Python 3.3+
  • (Optional) redis for the Redis backend
  • FUTURE (Optional) beanstalkc for the Beanstalk backend


  • Because I have NIH-syndrome.
  • Or because I longed for something simple (~375 loc).
  • Or because I wanted something with tests (90%+ coverage) & docs.
  • Or because I wanted pluggable backends.
  • Or because testing some other queuing system was a pain.
  • Or because I’m an idiot.

Basic Usage

This example uses Django, but there’s nothing Django-specific about Alligator. You can use it with any Python code.

from alligator import Gator

from django.contrib.auth.models import User
from django.shortcuts import send_email

# Make a Gator instance.
# Under most circumstances, you would configure this in one place &
# import that instance instead.
gator = Gator('redis://localhost:6379/0')

# The task itself.
# Nothing special, just a plain *undecorated* function.
def follow_email(followee_username, follower_username):
    followee = User.objects.get(username=followee_username)
    follower = User.objects.get(username=follower_username)

    subject = 'You got followed!'
    message = 'Hey {}, you just got followed by {}! Whoohoo!'.format(
    send_email(subject, message, '', [])

# An simple, previously expensive view.
def follow(request, username):
    # You'd import the task function above.
    if request.method == 'POST':
        # Schedule the task.
        # Use args & kwargs as normal.
        gator.task(follow_email, request.user.username, username)
        return redirect('...')

Running Tasks

Rather than trying to do autodiscovery, fanout, etc., you control how your workers are configured & what they consumer. Create a new executable file (bin script, management command, whatever) & drop in the following code.

from alligator import Gator, Worker

# Bonus points if you import that one pre-configured ``Gator`` instead.
gator = Gator('redis://localhost:6379/0')

# Consume & handle all tasks.
worker = Worker(gator)



Complex Usage (For Future Docs)

# We're re-using the above imports/setup.

def log_func(job):
    # A simple example of logging a failed task.
    if job.result != SUCCESS:
        logging.error("Job {} failed.".format(

# A context manager for supplying options
with gator.options(retries=3, async=settings.ASYNC_TASKS, on_error=log_func) as task:
    feeds_job = task(sketchy_fetch_feeds, timeout=30)

# Future wishlist items...

# Dependent tasks, will only run if the listed tasks succeed.
with gator.options(depends_on=[feeds_job]) as task:

# Delayed tasks (run in an hour).
with gator.options(run_after=60 * 60) as task:

Running Tests

$ virtualenv env2
$ . env2/bin/activate
$ pip install -r requirements.txt
$ python develop
$ py.test -s -v --cov=alligator --cov-report=html tests


  • Scheduled tasks
  • Dependent tasks
  • Cancellable tasks
Release History

Release History

History Node


History Node


History Node


History Node


History Node


History Node


History Node


This version
History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
alligator-0.5.0-py2.py3-none-any.whl (13.6 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Jan 1, 2015
alligator-0.5.0.tar.gz (217.1 kB) Copy SHA256 Checksum SHA256 Source Jan 1, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting