Skip to main content

A Django application that 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 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.

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 }}"
      }
    }
  ],
  "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 }}"
      }
    },
    {
      "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 }}"
      }
    },
    {
      "name": "my-other-msg-broker-config",
      "parameters": {
        "sale_id": "{{ myapp.utils.get_sale_id }}"
      }
    }
  ],
  "active": true
}

Documentation

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

License

This project is licensed under the MIT License - see the 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.2.0.tar.gz (19.6 kB view details)

Uploaded Source

Built Distribution

django_action_triggers-0.2.0-py3-none-any.whl (29.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_action_triggers-0.2.0.tar.gz
  • Upload date:
  • Size: 19.6 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.2.0.tar.gz
Algorithm Hash digest
SHA256 39775442a82c18ca97f3748c06c3db43222d5024f4b9195efd47282d33b41af1
MD5 419df8575aed0cdfb85757003e36344b
BLAKE2b-256 af28dc60037b7462f2678b6a6335a7e6b33147274078cc474999dc9c998e74c2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_action_triggers-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 29.1 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70d7d5904447db43d586ede4eea22609bc69281c1f5316f155d951cf00c40fb9
MD5 031e1507f967929d4bd62c0e9f2935d0
BLAKE2b-256 bad44f71883a7c598aa0a2def12decc9b69db60778971cc12ba7612eedf849e8

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