Skip to main content

A Temporal workflow task queue backend for Django 6.0's built-in task framework

Project description

django-tasks-temporal

License: MIT

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

  1. Add django_tasks_temporal to your INSTALLED_APPS:
INSTALLED_APPS = [
    # ...
    "django_tasks_temporal",
]
  1. 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)
        },
    },
}
  1. Define a task:
from django.tasks import task

@task
def send_email(to: str, subject: str, body: str):
    # Send email logic here
    pass
  1. Enqueue the task:
result = send_email.enqueue("user@example.com", "Hello", "World")
print(f"Task ID: {result.id}")
  1. 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_host is required.
  • namespace defaults to "default" if omitted.
  • task_queue defaults to "django-tasks" if omitted.
  • max_concurrent_workflow_tasks and max_concurrent_activities default to None, 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 from settings.TASKS. Defaults to default.
  • --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 tasks
  • POST /tasks/run-one/ - Process a single task
  • POST /tasks/execute/<task_id>/ - Execute specific task by ID
  • GET /tasks/status/<task_id>/ - Get task status
  • POST /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


Download files

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

Source Distribution

django_tasks_temporal-0.1.0.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

django_tasks_temporal-0.1.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

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

Hashes for django_tasks_temporal-0.1.0.tar.gz
Algorithm Hash digest
SHA256 204475c57ddfa975c34d45ad52eab272e0c6c8c74417e804da63ad73ebed8200
MD5 859720fb3080b2cd679df648e7574c44
BLAKE2b-256 967b80ababe9d6dda999eb9d06f07f918ab3e3378fb3d616b97a0099366a7ac6

See more details on using hashes here.

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

Hashes for django_tasks_temporal-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28b30061d8a713c0ce40993b65d6a5ec87d9c449a21a83f1e3694e7e64a8f3ea
MD5 efa4e7691d365ee228ec82b998cd9d5d
BLAKE2b-256 9b95516549d2ef0aaf1dc123f37c588bbaa1c6c8edc646b7f36e2389c0b7ebbd

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