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.

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
}

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.3.0.tar.gz (20.5 kB view details)

Uploaded Source

Built Distribution

django_action_triggers-0.3.0-py3-none-any.whl (29.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_action_triggers-0.3.0.tar.gz
  • Upload date:
  • Size: 20.5 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.3.0.tar.gz
Algorithm Hash digest
SHA256 e6e04304503bafb6cc70726994851d3cebefb3a1bd157deecbfb14cdd9da6ecb
MD5 581c494ac608c83036e2f07288265095
BLAKE2b-256 4028dc7b366d177e841f34071000af1d2d1730bad5beba2be755faf0b7cc324d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_action_triggers-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 29.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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d634ed5ea4340ba6ff34b4a94fbdd83681ba0866b1590ee22bcf24a13dfd922
MD5 7f60183b43aa7eb6a7c414e07876db79
BLAKE2b-256 85c8536ad0c2a82315b5eb0100af916721b01e79ce2515413a68786702785954

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