PyNotify is a flexible and extendable notification system that supports multiple notification channels like email and SMS.
Project description
PyNotify
PyNotify is a flexible and extendable notification system that supports multiple notification channels like email and SMS. It uses the Chain of Responsibility pattern to manage and process notifications.
Installation Guide
To install PyNotify, use pip:
pip install yaz_pynotify
Usage
Configuration
Before using the notification handlers, you need to configure the settings for email and SMS services.
from yaz_pynotify.notification_service.config import Settings, EmailSetting, SMSSetting
from yaz_pynotify.notification_service.config import Settings, EmailSetting, SMSSetting
email_settings = EmailSetting(
host='smtp.example.com',
port=587,
username='your-email@example.com',
password='your-email-password'
)
sms_settings = SMSSetting(
api_key='your-sms-api-key',
api_pwd='your-sms-api-password',
url='https://sms-api.example.com'
)
Settings.set(email_settings=email_settings, sms_settings=sms_settings)
Sending Notifications
Create message data and use the registered handlers to send notifications:
from yaz_pynotify.messaging_service.types import MessageData
from yaz_pynotify.notification_service.client import notify
from yaz_pynotify.messaging_service.types import MessageData
from yaz_pynotify.notification_service.client import notify
# Create message data
message_data = MessageData(
recipient="recipient@example.com",
subject="Test Notification",
body="This is a test message.",
is_html=False
)
# Send a notification
notify("email", message_data)
notify("sms", message_data)
Extending PyNotifa
To add a new notification channel, create a new handler by extending the NotificationHandler
abstract base class and implement the handle
method.
from yaz_pynotify.messaging_service.types import MessageData
from yaz_pynotify.notification_service.handlers.base import NotificationHandler
from yaz_pynotify.messaging_service.types import MessageData
from yaz_pynotify.notification_service.handlers.base import NotificationHandler
class CustomNotificationHandler(NotificationHandler):
kind = "custom"
def handle(self, kind: str, data: MessageData):
if kind == self.kind:
# Implement push notification logic here
print(f"Sending custom notification to {data.recipient}")
else:
# forward responsibility if the custom handler is unable to act on it
return self.forwardResponsibility(kind=kind, data=data)
Then, register the new handler:
from yaz_pynotify.notification_service.handlers.base import NotificationHandlerRegistry
from yaz_pynotify.messaging_service.types import MessageData
from yaz_pynotify.notification_service.client import notify
from yaz_pynotify.notification_service.handlers.base import NotificationHandlerRegistry
from yaz_pynotify.messaging_service.types import MessageData
from yaz_pynotify.notification_service.client import notify
from .customs import CustomNotificationHandler
NotificationHandlerRegistry.register(CustomNotificationHandler())
# Create message data
message_data = MessageData(
recipient="recipient@example.com",
subject="Test Notification",
body="This is a test message.",
is_html=False
)
# Send a notification
notify("email", message_data)
notify("sms", message_data)
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
File details
Details for the file yaz_pynotify-0.0.1.tar.gz
.
File metadata
- Download URL: yaz_pynotify-0.0.1.tar.gz
- Upload date:
- Size: 8.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
4e38ace512be402c87dbeed3d43c3b24d1c9dce8f7add02281c322027e2f79b7
|
|
MD5 |
3a0b7302adb7d87cf8656eb4b03c32bf
|
|
BLAKE2b-256 |
e6111510d5b316d6a06ab81450c1e490c58cc10753c48fbf2a49e50daa52ada5
|
File details
Details for the file yaz_pynotify-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: yaz_pynotify-0.0.1-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
9ba142cb4403e9084b9bd8cdfa26594eb7aa2b8cc70442a16978bbbfb0cabdcf
|
|
MD5 |
79ed5f92967867cc00c01fa32b5c306e
|
|
BLAKE2b-256 |
99788a710987dc76bb500ed288dfff9007aa51a26ccd54ed5639ebe711608b81
|