A Django package to map and visualize signal connections
Project description
Django SignalMap
Django SignalMap is a lightweight Django package that automatically tracks, maps, and visualizes the signal connections in your Django project. By monkey-patching Django's signal connect method, SignalMap records which receivers are attached to each signal and provides a management command to display this map in an easy-to-read format.
Features
-
Automatic Signal Tracking:
Records all signal registrations across your project without any manual configuration. -
Management Command:
Runpython manage.py signalmapto print a detailed overview of signals and their connected receiver functions. -
Custom Signal Names:
Easily assign friendly names to your custom signals for better readability in the output. -
Lightweight & Non-Intrusive:
Designed to work in development mode without affecting production performance. -
Open Source & Community-Driven:
Contributions, improvements, and feedback are welcome!
Installation
-
Install via pip:
pip install django-signalmap
-
Add to your INSTALLED_APPS:
In your project's settings.py, add the following line:
INSTALLED_APPS = [ # ... other installed apps ... 'django_signalmap.apps.DjangoSignalMapConfig', ]
Usage
Registering Signals
Ensure that your app's signals are imported so that they are registered. For example, in your app's apps.py:
# myapp/apps.py
from django.apps import AppConfig
class MyAppConfig(AppConfig):
name = 'myapp'
def ready(self):
# Import the signals module to register signals
import myapp.signals
Example Signal
Create a signals.py file in your app (e.g., myapp/signals.py):
# myapp/signals.py
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.contrib.auth.models import User
@receiver(post_save, sender=User)
def user_saved(sender, instance, **kwargs):
print("User saved!")
Viewing the Signal Map
After your signals are registered (for example, after running your server or a shell session), run:
python manage.py signalmap
You should see output similar to:
Signal: <django.dispatch.dispatcher.Signal object at 0x...>
-> Receiver: user_saved
Testing
To better see the results, you can add additional custom signals and receivers to your signals.py file:
from django.dispatch import Signal, receiver
# Custom signal (providing_args is no longer required in Django 3.1+)
order_processed = Signal()
order_processed.name = "order_processed"
@receiver(order_processed)
def notify_customer(sender, order_id, status, **kwargs):
print(f"Notify customer: Order {order_id} is now {status}.")
@receiver(order_processed)
def update_inventory(sender, order_id, status, **kwargs):
print(f"Update inventory for Order {order_id} after status {status}.")
# Another custom signal for testing purposes
data_imported = Signal()
data_imported.name = "data_imported"
@receiver(data_imported)
def log_import(sender, data_source, **kwargs):
print(f"Data imported from {data_source}.")
Then trigger the signals in a Django shell:
python manage.py shell
Within the shell, run:
from myapp.signals import order_processed, data_imported
order_processed.send(sender=None, order_id=1234, status='processed')
data_imported.send(sender=None, data_source='CSV file')
And run the management command again:
python manage.py signalmap
Contributing
Contributions are welcome! If you have suggestions, bug fixes, or improvements, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature-name). - Commit your changes.
- Push your branch.
- Open a pull request on GitHub.
For any issues or feature requests, please open an issue in the GitHub repository.
License
This project is licensed under the MIT License.
Contact
For questions, suggestions, or support, please contact ibrahim.muhaisen.2015@gmail.com.
Happy coding!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_signalmap-0.1.1.tar.gz.
File metadata
- Download URL: django_signalmap-0.1.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7a4705d5c2251d8c19db812d50573e29f72383a97f2ccb6b6648c604eb5ea99
|
|
| MD5 |
7b9519eb6aee9ca4e188ca00cfbd2d7e
|
|
| BLAKE2b-256 |
dee9eb1c31f562842587a6adb65e1c1882f120e027108852949023da190ebceb
|
File details
Details for the file django_signalmap-0.1.1-py3-none-any.whl.
File metadata
- Download URL: django_signalmap-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.8.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3616921cc1cf96e816a97542e8d7f5266196454c5dc172ef35e6445ec9a50844
|
|
| MD5 |
32a5260dcecbda34de4cc3f2aa78cb44
|
|
| BLAKE2b-256 |
fd68e5d571ae7e25cd5642d8b31b68b0be5d9dea189c5cd5f95c339440ec2169
|