A Temporal workflow task queue backend for Django 6.0's built-in task framework
Project description
django-tasks-temporal
A Temporal task queue backend for Django 6.0's built-in task framework.
Features
- Full integration with Django 6.0's task framework (
django.tasks) - Delayed task execution with scheduled times
- Priority-based task processing
- Crash recovery with automatic task reclaim
- Django Admin integration for task monitoring and management
- HTTP endpoints for external triggers (webhooks, Cloud Scheduler, etc.)
Architecture
sequenceDiagram
participant App as Application
participant Backend as TemporalTaskBackend
participant Temporal as Temporal Server
participant Worker as Worker Process
App->>Backend: task.enqueue(*args, **kwargs)
Backend->>Temporal: start workflow
Temporal-->>App: TaskResult(id, status=READY)
Worker->>Temporal: poll task queue
Temporal-->>Worker: RunDjangoTaskWorkflow
Worker->>Worker: run Django task activity
Worker->>Temporal: complete or fail workflow
App->>Backend: backend.get_result(task_id)
Backend->>Temporal: describe workflow / fetch result
Temporal-->>Backend: workflow status and result
Backend-->>App: TaskResult(status, errors, return_value)
Requirements
- Python 3.12+
- Django 6.0+
Installation
uv add django-tasks-temporal
Start a local Temporal server for development:
docker compose up -d
This repository also includes a convenience target:
just infra-up
Quick Start
- Add
django_tasks_temporalto yourINSTALLED_APPS:
INSTALLED_APPS = [
# ...
"django_tasks_temporal",
]
- Configure the task backend in your Django settings:
TASKS = {
"default": {
"BACKEND": "django_tasks_temporal.TemporalTaskBackend",
"QUEUES": [], # Empty list = allow all queue names
"OPTIONS": {
"target_host": "localhost:7233",
# Temporal connection options (e.g. host, namespace)
},
},
}
- Define a task:
from django.tasks import task
@task
def send_email(to: str, subject: str, body: str):
# Send email logic here
pass
- Enqueue the task:
result = send_email.enqueue("user@example.com", "Hello", "World")
print(f"Task ID: {result.id}")
- Run the worker:
python manage.py run_temporal_worker
5.a
Alternatively you can start a worker directly without manage.py:
DJANGO_SETTINGS_MODULE="your-django.settings" python -m django_tasks_temporal.worker
Configuration Options
TASKS = {
"default": {
"BACKEND": "django_tasks_temporal.TemporalTaskBackend",
"QUEUES": [], # Empty list = allow all queue names
"OPTIONS": {
"target_host": "localhost:7233", # Temporal server address
"namespace": "default", # Temporal namespace
"task_queue": "django-tasks", # Temporal task queue name
"max_concurrent_workflow_tasks": None, # Omit or set to None for Temporal defaults
"max_concurrent_activities": None, # Omit or set to None for Temporal defaults
},
},
}
Notes:
target_hostis required.namespacedefaults to"default"if omitted.task_queuedefaults to"django-tasks"if omitted.max_concurrent_workflow_tasksandmax_concurrent_activitiesdefault toNone, which lets Temporal use its defaults.
Management Commands
run_temporal_worker
Start a worker to process tasks:
python manage.py run_temporal_worker [--backend BACKEND] [--no-fallback]
Options:
--backend: Select the Django task backend fromsettings.TASKS. Defaults todefault.--no-fallback: Disable the clean-subprocess retry used when in-process worker startup fails because of an import or sandbox conflict.
You can also run the worker module directly:
DJANGO_SETTINGS_MODULE="your_django_project.settings" python -m django_tasks_temporal.worker --backend default
Available endpoints:
POST /tasks/run/- Process multiple tasksPOST /tasks/run-one/- Process a single taskPOST /tasks/execute/<task_id>/- Execute specific task by IDGET /tasks/status/<task_id>/- Get task statusPOST /tasks/purge/- Purge completed tasks
Public API
django_tasks_temporal.TemporalTaskBackend: Django task backend implementation for Temporal.python manage.py run_temporal_worker: Management command for running a Temporal worker.python -m django_tasks_temporal.worker: Module entrypoint for running a worker directly.
Development
Run checks and tests locally:
just test
just lint
License
MIT License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_tasks_temporal-0.1.0.tar.gz.
File metadata
- Download URL: django_tasks_temporal-0.1.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
204475c57ddfa975c34d45ad52eab272e0c6c8c74417e804da63ad73ebed8200
|
|
| MD5 |
859720fb3080b2cd679df648e7574c44
|
|
| BLAKE2b-256 |
967b80ababe9d6dda999eb9d06f07f918ab3e3378fb3d616b97a0099366a7ac6
|
File details
Details for the file django_tasks_temporal-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_tasks_temporal-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
28b30061d8a713c0ce40993b65d6a5ec87d9c449a21a83f1e3694e7e64a8f3ea
|
|
| MD5 |
efa4e7691d365ee228ec82b998cd9d5d
|
|
| BLAKE2b-256 |
9b95516549d2ef0aaf1dc123f37c588bbaa1c6c8edc646b7f36e2389c0b7ebbd
|