Hi everyone,
Django 6 ships django.tasks, a standard API for background tasks, but leaves the worker to third parties. I’ve been building tinyjobs, an open source job queue for Python, and it now includes a django.tasks backend plus the worker to run it.
The idea is that you don’t need a broker to start: the queue is a SQLite file. When you outgrow one machine you switch the URL to Redis and your task code stays the same.
# settings.py
INSTALLED_APPS = [..., "tinyjobs.contrib.django"]
TASKS = {
"default": {
"BACKEND": "tinyjobs.contrib.django.TinyJobsBackend",
"OPTIONS": {"url": "sqlite:///jobs.db"},
}
}
# shop/tasks.py
from django.tasks import task
@task
def send_receipt(order_id: int) -> None:
...
send_receipt.enqueue(42)
python manage.py tinyjobs worker
What works today: queues, priorities, run_after, async tasks, takes_context, get_result(), and the task_enqueued / task_started / task_finished signals. manage.py tinyjobs also gives you jobs, stats and check for inspecting the queue and for health probes.
A few design choices you may care about:
- Tasks are resolved by import path, and only inside your
INSTALLED_APPS, so a job can never make the worker import code your project doesn’t already trust. - Arguments are JSON, as
django.tasksexpects; there’s no pickle. - Delivery is at-least-once: if a worker dies mid-task, its lease expires and the task is marked
FAILED, since Django tasks aren’t retried. - The queue lives outside your database, so an enqueue can’t share your transaction. Use
transaction.on_commit. If you need transactional enqueue through the ORM today, django-tasks-db is the better fit.
I tested it with a real project under uvicorn --workers 2 and under runserver: 1,000 requests across sync and async views, each enqueuing a task that writes a row, with two workers on SQLite and then on Redis. Every task ran exactly once. Enqueueing through django.tasks costs about the same as calling tinyjobs directly, around 6,000 per second.
- Repo: GitHub - Piergiuseppe/tinyjobs: Background jobs and cron for Python, on SQLite, with zero dependencies · GitHub
- PyPI:
pip install tinyjobs(zero dependencies, Python 3.12+)
I’d really appreciate feedback, especially from anyone who has been following django.tasks: what you’d expect from a backend, and anything that doesn’t feel Django-like.