Skip to main content

A Django application that asynchronously triggers actions based on database changes. Supports webhook integration, message brokers (Kafka, RabbitMQ), and flexible configurations.

Project description

Django Action Triggers

License: MIT PyPI version codecov PyPI - Supported Python Versions Supported Django Versions

Table of Contents

Description

Django Action Triggers is a Django application that allows you to asynchronously trigger actions based on changes in your database. These actions can include sending a request to a webhook or adding a message to a message broker such as Kafka or RabbitMQ.

This application is highly flexible and can be configured via code or through the Django admin interface.

Key Features

  • Database-Driven Triggers: Automatically trigger actions based on model events (e.g., save, delete).
  • Webhook Integration: Send HTTP requests to external services when triggers are activated.
  • Message Broker Integration: Send messages to messaging brokers like Kafka and RabbitMQ.
  • Extensible: Easily extend to support custom triggers and actions.
  • Secure Dynamic Configuration: Dynamically set values at runtime for secure and flexible configuration.

Documentation

For detailed documentation, including setup, configuration options, API specifications, and more examples, please refer to the official documentation.

Supported Message Brokers

  • Kafka
  • RabbitMQ
  • Redis
  • AWS SQS (Amazon Simple Queue Service)
  • AWS SNS (Amazon Simple Notification Service)

Need support for another message broker? Please submit a feature request on the GitHub repository.

Installation

To install the package, run the following command:

pip install django-action-triggers

Then, add the following to your INSTALLED_APPS in your Django settings:

INSTALLED_APPS = [
    ...
    'action_triggers',
    ...
]

If you plan on using the API, add the following to your urls.py:

from django.urls import path, include

urlpatterns = [
    ...
    path('api/action-triggers/', include('action_triggers.urls')),
    ...
]

Usage

Once installed, you can create triggers and actions using the Django admin interface or programmatically through the API.

For detailed usage instructions, configuration options, and examples, please refer to the official documentation.

Example Scenarios

Example 1: Webhook Trigger on User Creation/Update/Deletion

Trigger a webhook whenever a User model is created, updated, or deleted:

{
  "config_signals": [
    {"signal": "post_save"},
    {"signal": "post_delete"}
  ],
  "content_types": [
    {
      "app_label": "auth",
      "model_name": "User"
    }
  ],
  "webhooks": [
    {
      "url": "https://my-webhook.com",
      "http_method": "POST",
      "headers": {
        "Authorization": "Bearer {{ myapp.utils.get_token }}"
      },
      "timeout_secs": 22.5
    }
  ],
  "active": true
}

Example 2: Webhooks and Message Queues on Product and Sale Creation/Update

Trigger multiple webhooks and add messages to queues when Product or Sale models are created or updated:

{
  "config_signals": [
    {"signal": "post_save"}
  ],
  "content_types": [
    {
      "app_label": "myapp",
      "model_name": "Product"
    },
    {
      "app_label": "myapp",
      "model_name": "Sale"
    }
  ],
  "webhooks": [
    {
      "url": "https://my-webhook.com",
      "http_method": "POST",
      "headers": {
        "Authorization": "Bearer {{ myapp.utils.get_token }}"
      },
      "timeout_secs": 10.5
    },
    {
      "url": "https://my-other-webhook.com",
      "http_method": "POST",
      "headers": {
        "Authorization": "Bearer {{ myapp.utils.get_token }}"
      }
    }
  ],
  "msg_broker_queues": [
    {
      "name": "my-msg-broker-config",
      "parameters": {
        "product_id": "{{ myapp.utils.get_product_id }}"
      },
      "timeout_secs": 2.5
    },
    {
      "name": "my-other-msg-broker-config",
      "parameters": {
        "sale_id": "{{ myapp.utils.get_sale_id }}"
      }
    }
  ],
  "active": true
}

Don't See What You're Looking For?

If you have any feature requests or issues, please submit them to the GitHub repository. This also helps us prioritise new features and bug fixes.

License

This project is licensed under the MIT License - see LICENSE file for details.

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_action_triggers-0.4.0.tar.gz (25.4 kB view details)

Uploaded Source

Built Distribution

django_action_triggers-0.4.0-py3-none-any.whl (37.8 kB view details)

Uploaded Python 3

File details

Details for the file django_action_triggers-0.4.0.tar.gz.

File metadata

  • Download URL: django_action_triggers-0.4.0.tar.gz
  • Upload date:
  • Size: 25.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for django_action_triggers-0.4.0.tar.gz
Algorithm Hash digest
SHA256 72e391a67a7ab907c38c03dd1036361ebebe9f0d49578e52180a6ba95d6bc6ad
MD5 dc14f231b043ab3f481ce312ef75f5f2
BLAKE2b-256 2ad97c6246ff89cde8df5c18b0651fcbc79468190708b5ab281f57c6265b4f93

See more details on using hashes here.

File details

Details for the file django_action_triggers-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: django_action_triggers-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 37.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.5 Linux/5.15.153.1-microsoft-standard-WSL2

File hashes

Hashes for django_action_triggers-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bfe188d32c0c861e9d4543c0722de6da2ca73b8dbd9ce6fd3c530f5db4114665
MD5 a5d167543d0aa117d037ea8ba666a0c7
BLAKE2b-256 410274e20f28b692930d8e75ca7ff24b713265768130c43732954a47fc1b5511

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page