Registry / web-framework / django-tasks

django-tasks

JSON →
library0.12.0pypypi✓ verified 33d ago

A backport of Django's built-in Tasks framework, `django-tasks` provides a robust way to run asynchronous background tasks within Django applications. As of version 0.12.0, it focuses on mirroring the upstream `django.tasks` package, with backends like DB and RQ now available as separate packages. It maintains an active release cadence, frequently updating to support new Django and Python versions.

web-frameworkdatabaseworkflow
Install & Compatibility
Where this runs
tested against v0.12.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
4/5 runs
4/5 runs
py 3.11
4/5 runs
4/5 runs
py 3.12
4/5 runs
4/5 runs
py 3.13
4/5 runs
4/5 runs
py 3.9
4/5 runs
4/5 runs
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

from django_tasks import task

This quickstart demonstrates how to define a task using the `@task` decorator and enqueue it for asynchronous execution using `.delay()`. It includes a minimal Django configuration for testing, assuming the `django-tasks-db` backend is used and installed.

import os from django.conf import settings # Minimal Django setup for demonstration if not settings.configured: settings.configure( INSTALLED_APPS=[ 'django.contrib.auth', 'django.contrib.contenttypes', 'tasks' # Ensure 'tasks' is in INSTALLED_APPS ], DATABASES={ 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:', } }, TASKS_BACKEND='tasks_db.backends.DatabaseBackend', # Or 'tasks_rq.backends.RQBackend' USE_TZ=True ) # Ensure migrations are run for tasks_db if using it # In a real project, this would be part of `manage.py migrate` import django django.setup() # This part assumes django-tasks-db is installed for the example # and that tasks.backends is configured. # For a true quickstart, you'd run `python manage.py makemigrations tasks_db && python manage.py migrate` from tasks import task @task def greet_user(name): print(f"Hello, {name}!") return f"Greeting for {name} completed." # Enqueue the task for asynchronous execution result = greet_user.delay("World") print(f"Task enqueued with ID: {result.pk}") # To process the task (typically run by a worker process) # For local testing, you might manually run the task # from tasks import run_task # run_task(result.pk) # You can inspect the result object (needs refresh if worker is separate) # result.refresh_from_db() # print(f"Task status: {result.status}") # print(f"Task result: {result.result}")
Debug
Known footguns
breakingIn version `0.12.0`, the Database and RQ backends were extracted into separate packages (`django-tasks-db` and `django-tasks-rq`). If you previously used these backends, `django-tasks` no longer includes them directly.
breakingThe `enqueue_on_commit` functionality was removed in version `0.10.0`.
breakingIn version `0.8.0`, the `TaskResult` status `NEW` was renamed to `READY` to better support retry functionality. Additionally, exceptions and tracebacks are now stored in a `.errors` list on the `TaskResult` model, rather than directly on `exception` and `traceback` attributes.
breakingIn version `0.6.0`, the `TaskResult` status `completed` was renamed to `succeeded`.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
14 hits · last 30 days
gptbot
4
ahrefsbot
4
bytedance
2
dotbot
1
Resources