Skip to main content

django_tasks_pubsub

Google Cloud Pub/Sub backend for Django tasks

Installation

Package manager

pip

pip install django_tasks_pubsub

uv

uv add django_tasks_pubsub

Add to INSTALLED_APPS

INSTALLED_APPS = [
    ...
    "django_tasks_pubsub",
]

Settings

Idempotency check

add to settings what prefix you want for me to check idempotency

this will ensure that the task is not executed multiple times for the same message

uses django cache framework to check status of ongoing tasks

PUBSUB_CACHE_PREFIX = 'some_prefix'

Add required Google Cloud Pub/Sub settings

PUBSUB_PROJECT_ID = "your-google-cloud-project-id"
PUBSUB_DEFAULT_TOPIC_ID = "your-default-topic-id"

Optional telemetry propagation hooks

The queue layer stays telemetry-agnostic. If your app wants to propagate tracing information via message attributes, configure a getter and a restorer hook.

# settings.py
DJANGO_TASKS_PUBSUB_TRACE_PROPAGATION_GETTER = "myapp.telemetry.get_message_trace_metadata"
DJANGO_TASKS_PUBSUB_TRACE_PROPAGATION_RESTORER = "myapp.telemetry.restore_trace_context"
# myapp/telemetry.py
def get_message_trace_metadata() -> dict[str, str]:
    return {
        "sentry-trace": sentry_sdk.get_traceparent(),
        "baggage": sentry_sdk.get_baggage() or "",
    }


def restore_trace_context(metadata: dict[str, str]) -> object:
    return sentry_sdk.continue_trace(metadata)

If no hook is configured, the library behaves as a no-op and sends no tracing attributes or context restoration.

Add the backend to the TASKS setting

TASKS = {
    "default": {
        "BACKEND": "django_tasks_pubsub.PubSubBackend",
    }
}

Authentication

Check out the Google Cloud Pub/Sub documentation for more information.

In short the the client works well within a Google Cloud environment.

URLs

In order to receive push messages from Google Cloud Pub/Sub, you need to register the endpoint in your project's urls.py:

from django.urls import path, include

urlpatterns = [
    ...
    path("", include("django_tasks_pubsub.urls")),
]

This will expose the endpoint at /pubsub/push/. You should configure your Google Cloud Pub/Sub push subscription to use this endpoint (e.g. https://your-domain.com/pubsub/push/).

Usage

Configure Django task functions

from django.tasks import task

@task
def send_email(user_id):
    print(f"Sending email to {user_id}")

Configure specifics for the task

Specify a topic

To specify a topic, you need to decorate the task with @task and @pubsub_task(topic="topic-name") in this order:

from django.tasks import task
from django_tasks_pubsub import pubsub_task


@task
@pubsub_task(topic_id="images")
def function(image_id: int):
    ...

Development

Commit Messages

All commits to this repository must follow the Conventional Commits specification.

This is required because the automated release and tagging workflow relies on conventional commit prefixes (such as feat:, fix:, chore:, docs:, etc.) to automatically calculate the next semantic version.

License

MIT

Metadata

Release files for django-tasks-pubsub 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-tasks-pubsub 0.5.0
File Size Uploaded Provenance Actions
django_tasks_pubsub-0.5.0.tar.gz 13.5 kB With provenance Details for django_tasks_pubsub-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-tasks-pubsub 0.5.0
File Interpreter ABI Platform Actions
django_tasks_pubsub-0.5.0-py3-none-any.whl Python 3 none any Details for django_tasks_pubsub-0.5.0-py3-none-any.whl

Total release size: 22.8 kB

Release files / django_tasks_pubsub-0.5.0.tar.gz

Download URL django_tasks_pubsub-0.5.0.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3a929e9294cc149970c31e0b84d0b27e94ef4d22bde5cea4a19309566da3738c
BLAKE2b-256 checksum
How to use checksums
4865a37157cdbdd4ff588b82ab16516abc2b409f79d29e53594e2641e7c4909e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.

Transparency log

Release files / django_tasks_pubsub-0.5.0-py3-none-any.whl

Download URL django_tasks_pubsub-0.5.0-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
091224621fb4f6605398a371fce794bf7c637abdba846c719127b2530ce62440
BLAKE2b-256 checksum
How to use checksums
6124bef42cd3de86c4ba3300be7ed9e215dd2a233ad39e3df1d52e631e5787f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.

Transparency log

Security for django-tasks-pubsub 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for django_tasks_pubsub-0.5.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 2, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page