Skip to main content

Salesforce-style lifecycle hooks for Django bulk operations

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

django-bulk-lifecycle

⚡ Salesforce-style lifecycle hooks for Django bulk operations.

django-bulk-lifecycle brings a declarative, trigger-like experience to Django's bulk_create, bulk_update, and bulk_delete — including support for BEFORE_ and AFTER_ hooks, conditions, batching, and transactional safety.

✨ Features

  • Declarative hook system: @hook(AFTER_UPDATE, condition=...)
  • BEFORE/AFTER hooks for create, update, delete
  • Salesforce-style semantics with full batch support
  • Lifecycle-aware manager that wraps Django’s bulk_ operations
  • Hook chaining, trigger deduplication, and atomicity
  • Class-based hook handlers with DI support

🚀 Quickstart

pip install django-bulk-lifecycle

Define Your Model

from django.db import models
from django_bulk_lifecycle.manager import BulkLifecycleManager

class Account(models.Model):
    balance = models.DecimalField(max_digits=10, decimal_places=2)
    objects = BulkLifecycleManager()

Create a Trigger Handler

from django_bulk_lifecycle import hook, AFTER_UPDATE, TriggerHandler
from django_bulk_lifecycle.conditions import WhenFieldHasChanged
from .models import Account

class AccountTriggerHandler(TriggerHandler):
    @hook(AFTER_UPDATE, model=Account, condition=WhenFieldHasChanged("balance"))
    def log_balance_change(self, new_objs):
        print("Accounts updated:", [a.pk for a in new_objs])

🛠 Supported Lifecycle Events

  • BEFORE_CREATE, AFTER_CREATE
  • BEFORE_UPDATE, AFTER_UPDATE
  • BEFORE_DELETE, AFTER_DELETE

🧠 Why?

Django’s bulk_ methods bypass signals and save(). This package fills that gap with:

  • Triggers that behave consistently across creates/updates/deletes
  • Scalable performance via chunking (default 200)
  • Support for @hook decorators and centralized trigger classes

📦 Usage in Views / Commands

# Calls AFTER_UPDATE hooks automatically
Account.objects.bulk_update(accounts, ['balance'])

# Triggers BEFORE_CREATE and AFTER_CREATE
Account.objects.bulk_create(accounts)

🧩 Integration with Queryable Properties

You can extend from BulkLifecycleManager to support formula fields or property querying.

class MyManager(BulkLifecycleManager, QueryablePropertiesManager):
    pass

📝 License

MIT © 2024 Augend / Konrad Beck

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_bulk_lifecycle-0.1.50.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_bulk_lifecycle-0.1.50-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file django_bulk_lifecycle-0.1.50.tar.gz.

File metadata

  • Download URL: django_bulk_lifecycle-0.1.50.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.11.9 Windows/10

File hashes

Hashes for django_bulk_lifecycle-0.1.50.tar.gz
Algorithm Hash digest
SHA256 b93a1d3d3b328d412a43d180e9d8dbfc12356cc0c6744a40c77909a538f1fb5a
MD5 c146134fc4b30a4b90ed8ab6324d1b50
BLAKE2b-256 b1ec7b548733467d43dde1e35cb608167ed9ed41e895fe0a66858249d70f0aa9

See more details on using hashes here.

File details

Details for the file django_bulk_lifecycle-0.1.50-py3-none-any.whl.

File metadata

File hashes

Hashes for django_bulk_lifecycle-0.1.50-py3-none-any.whl
Algorithm Hash digest
SHA256 e56cdf253aee7e437ff50026334bbf83c55cca13a6bdc6cec9ed3f0abed8c28a
MD5 b01e3eeab59cef15334233158bf57e9f
BLAKE2b-256 db14c9160e75a2e8e5724af4b6491fa21d38ee67e825f43a236e8ae9d5029577

See more details on using hashes here.

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