Skip to main content

Django tasks backend for Google Cloud Pub/Sub

Project description

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

Add required Google Cloud Pub/Sub settings

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

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="images")
def function(image_id):
    ...

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

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_pubsub-0.1.8.tar.gz (9.5 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_pubsub-0.1.8-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file django_tasks_pubsub-0.1.8.tar.gz.

File metadata

  • Download URL: django_tasks_pubsub-0.1.8.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_tasks_pubsub-0.1.8.tar.gz
Algorithm Hash digest
SHA256 84b9e207cf643a09cf8dc801fe4080f38fc62c801909f21537490395bfd5cda2
MD5 09ef5aca0c0f3df2b98567d9a3e7b645
BLAKE2b-256 0ee00bbecd30ccc7127c858b29344f1f74717e2a7e9f49246aa78dfd07b20126

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_tasks_pubsub-0.1.8.tar.gz:

Publisher: create_tag_and_release.yml on joelbitar/django_tasks_pubsub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file django_tasks_pubsub-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for django_tasks_pubsub-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 54d5d9a2520aa1769613fd21863e96ec2a0210c842f8b5946aaf5c6307e7df92
MD5 b3ad0e999be76024e8514e28ed9794c8
BLAKE2b-256 54de2b19270ea1fdd526a85bd3ffd5d55158a9e4e6f7cc61002aafb01e420fc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_tasks_pubsub-0.1.8-py3-none-any.whl:

Publisher: create_tag_and_release.yml on joelbitar/django_tasks_pubsub

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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