Skip to main content

Django Unified Signals

Continuous Integration

This package extends behavior of the Django Signals, by unifying the data passed when the signal is sent. That way both: the sender and the receiver can be sure that the data passed is always of the same type.

Django Signals are not very strict on the data that can be passed with send method. Basically anything can be passed as the arguments and receivers need to be aware of that from the project documentation. It gets even worse when on one side the signal send params change and the receivers' maintainers may not be aware of that. It gets even worse, when using send_robust method, which ignores all exceptions and any errors may pass without being noticed.

Using this package you have to define the message type class which object
is always expected to be passed when sending the signal. That way receiver knows what type of message will be received. This package automates the process of checking if the send message is following the contract.

Installation

The package is available on PyPI:

pip install django-unified-signals

Usage

Let's start by defining the message structure. It can be any class you want. In the example we will use dataclass:

import dataclasses

@dataclasses.dataclass
class UserMessage:
    name: str
    age: int

Now that we have the message structure defined, we can create the signal:

from unified_signals import UnifiedSignal

user_deactivated_signal = UnifiedSignal(UserMessage)

It extends the standard django.dispatch.Signal class, so it can be used in the same way.

user_deactivated_signal.send(sender, UserMessage(name='John', age=30))

The receiver can be defined in the same way as for the standard Django Signal:

@receiver(user_deactivated_signal)
def handle_user_deactivated(sender, message: UserMessage, **kwargs):
    print(message.name)
    print(message.age)
    ...

The difference is that the message is always of the same type, so the receiver can be sure that the message is always of the same type. If the message is not of the expected type when sending the signal, the unified_signals.exceptions.UnifiedSignalMessageTypeError exception will be raised.

user_deactivated_signal.send(sender, 'not a message') # raises UnifiedSignalMessageTypeError

Contributing

Commits must follow Conventional Commits (feat:, fix:, chore:, etc.) — enforced locally via pre-commit install (installs both the pre-commit and commit-msg hooks). They drive automated version bumps and changelog generation via python-semantic-release.

Releasing

Run the Release workflow manually from the Actions tab (targets master) whenever the changes on master are ready to ship. It computes the next version from commit history, bumps pyproject.toml, updates CHANGELOG.md, tags the commit, and publishes a GitHub Release. Publishing to PyPI is still done manually.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_unified_signals-0.4.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

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

django_unified_signals-0.4.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_unified_signals-0.4.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for django_unified_signals-0.4.0.tar.gz
Algorithm Hash digest
SHA256 b8f21b4aa1fc341d0c3655ae43ecc38ed5764a75da234aaa47b74dba195477b0
MD5 e3c0b85f8d547d2cc3970855de6f39b8
BLAKE2b-256 c0a3b162ed3957b41a0d7d8e3e9b6236dcd903118d9379b2d1c1ae54eaf0fbb1

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_unified_signals-0.4.0.tar.gz:

Publisher: publish-pypi.yaml on ivellios/django-unified-signals

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

File hashes

Hashes for django_unified_signals-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c737de0760ddd9f5a2ca829442daf97d1312ad4f76aad9104d081e05095c766
MD5 2359c80ecdbfac2d68e2dbed33edc7cf
BLAKE2b-256 b381afc176095f69b961a66308500dfaf6322cbcc427de3eec700044de0c040f

See more details on using hashes here.

Provenance

The following attestation bundles were made for django_unified_signals-0.4.0-py3-none-any.whl:

Publisher: publish-pypi.yaml on ivellios/django-unified-signals

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page