This mini–project demonstrates a pluggable notification framework written in modern Python.
-
Channels
- Email – mocked by writing files to an
outbox/directory - Slack – mocked by printing to the console
- Email – mocked by writing files to an
-
Templating – powered by Jinja2
-
Event sources
- Real-time (in-memory lists)
- Scheduled query (any callable, e.g. simulating SQL)
-
De-duplication – pluggable policy, includes an in-memory example
-
Registry – see every notification configuration in one place
pip install -r requirements.txt
python example.pyWatch the console for Slack messages and check the outbox/ folder for generated email files.
- Create or choose an
EventSource(e.g.,RealTimeEventSource). - Write a
Templatestring containing Jinja2 placeholders. - Select a
NotificationChannel(or implement a new one by subclassingNotificationChannel). - Assemble them into a
Notificationinstance and register it:
registry.register(Notification(
name="My Cool Notification",
channel=my_channel,
template=my_template,
event_source=my_source,
))- New channel – subclass
NotificationChanneland implementsend. - New event source – subclass
EventSourceand implementget_events. - New dedup policy – subclass
DedupPolicyand implementis_duplicate.
Because dependencies are injected via constructors, components are easy to unit-test in isolation.