Overview
An events framework that allows for logging and processing of Django models custom events.
See CHANGELOG.md for release notes.
Setup
Requirements
- Python 3.6+
Installation
Install it directly into an activated virtual environment:
$ pip install django-events-framework
Usage
After installation, the framework can be used by:
INSTALLED_APPS = [
...,
"events_framework"
]
Concurrency & Error Handling
- Concurrency: Processing uses database row locks via
select_for_update(skip_locked=True)to avoid double-processing across workers. Multiple workers can safely call theprocess_eventscommand. - Multiple handlers: All registered handlers for an
(EventModel, type)run for each event. If any handler raises, their database changes are rolled back and the event recordserror=Trueanderror_message. - Idempotency: Handlers should be idempotent, as retries or alternative processors may be added later.
- Retries: Ordinary exceptions mark the event as processed. Raise
events_framework.exceptions.RetryEventto leave it pending for the nextprocess_eventsinvocation. A successful retry clears the error fields. Each retry runs all handlers again, so external operations must tolerate repeated delivery. - Backoff: Processing makes one attempt per pending event per invocation. The command schedule controls the retry interval; there is no automatic retry limit or exponential backoff.
For a publisher, raise RetryEvent when the receiver cannot durably accept the event. Use the same event identity and immutable payload on every delivery attempt. Handlers run inside a database transaction, so use bounded network timeouts and acknowledge processing only after the receiver confirms durable acceptance:
from events_framework.decorators import register
from events_framework.exceptions import RetryEvent
@register(InvoiceEvent, InvoiceEvents.CHANGED)
def publish_invoice_change(event):
try:
publish(event.parameters)
except ReceiverUnavailable as error:
raise RetryEvent("Invoice event receiver unavailable") from error
publish and ReceiverUnavailable are supplied by the application. Create the event and its immutable payload in the same transaction as the business change. A receiver may accept an event before the sender fails to record success; the receiver must deduplicate repeated deliveries.
Tested combinations include Django 2.2, 3.2, and 4.2 on supported Python versions.
Quickstart
- Declare your events and model
# myapp/events.py
from events_framework.utils import AbstractEvents
class OrderEvents(AbstractEvents):
CREATED = "created"
FAILED = "failed"
CHOICES = [
(CREATED, "Order was created"),
(FAILED, "Order processing failed"),
]
# myapp/models.py
from django.db import models
from events_framework.models import EventModel
from .events import OrderEvents
class Order(models.Model):
number = models.CharField(max_length=32)
class OrderEvent(EventModel):
order = models.ForeignKey(Order, on_delete=models.CASCADE, related_name="events")
type = models.CharField(max_length=128, choices=OrderEvents.as_choices())
- Generate events in your app logic
# myapp/events/generators.py
from .events import OrderEvents
from ..models import OrderEvent
def created(order):
return OrderEvent.objects.create(order=order, type=OrderEvents.CREATED)
- Register processors with a decorator
# myapp/events/processors.py
from events_framework.decorators import register
from .events import OrderEvents
from ..models import OrderEvent
@register(OrderEvent, OrderEvents.CREATED)
def on_order_created(event):
# do something with event.order
...
- Enable auto-discovery of processors and run the worker
# settings.py
INSTALLED_APPS = [
...,
"events_framework",
"myapp",
]
EVENT_APPS = ["myapp"] # looks for myapp.events.processors
Run the processor:
python manage.py process_events
Metadata
Release files for django-events-framework 0.0.15
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django_events_framework-0.0.15.tar.gz | 6.9 kB | With provenance | Details for django_events_framework-0.0.15.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_events_framework-0.0.15-py3-none-any.whl | Python 3 | none | any | Details for django_events_framework-0.0.15-py3-none-any.whl |
Total release size: 15.2 kB
Release files / django_events_framework-0.0.15.tar.gz
| Download URL | django_events_framework-0.0.15.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
670aaf03cd28f4994bb4f4ed56aaf030768b8e0479865508d1fd472bc7c4b056
|
|
BLAKE2b-256 checksum How to use checksums |
076bbcfa0d1eaf8c11aa3fa04584cefdc8160b4e7c164431da7014e478e10496
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logRelease files / django_events_framework-0.0.15-py3-none-any.whl
| Download URL | django_events_framework-0.0.15-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
39e4f7bf3c35716ae7ece23053a2510578f48da7fa5d101bdedcbbd48a166949
|
|
BLAKE2b-256 checksum How to use checksums |
ccaa9b89785ae22333a16e1b84325eb6c8bd9a23a976d25c874888a01e44067b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logSecurity for django-events-framework 0.0.15
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for django_events_framework-0.0.15.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 20, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.