A Simple Python Module For Sending Cross-Platform Desktop Notifications

In this post, I am going to explain to you one simple python module for sending cross-platform desktop notifications.

notify.py

Cross platform desktop notifications for Python scripts and applications.

Supported Platforms:

  • Windows 10
  • macOS 10 >=10.10
  • Linux (libnotify)

No dependencies are required other than loguru & jeepney (Only for linux/DBUS).

Install:

pip install notify-py

Usage:

Send Simple Notification:

from notifypy import Notify

notification = Notify()
notification.title = "Cool Title"
notification.message = "Even cooler message."
notification.send()

Send Notification With Icon:

from notifypy import Notify

notification = Notify()
notification.title = "Cool Title"
notification.message = "Even cooler message."
notification.icon = "path/to/icon.png"

notification.send()

Send Notification With Sound

from notifypy import Notify

notification = Notify()
notification.title = "Cool Title"
notification.message = "Even cooler message."
notification.audio = "path/to/audio/file.wav"

notification.send()

Sending Notifications without blocking

from notifypy import Notify

notification = Notify()
notification.send(block=False)

Sending with Default Notification Titles/Messages/Icons

from notifypy import Notify

notification = Notify(
  default_notification_title="Function Message",
  default_application_name="Great Application",
  default_notification_icon="path/to/icon.png",
  default_notification_audio="path/to/sound.wav"
)

def your_function():
  # stuff happening here.
  notification.message = "Function Result"
  notification.send()

Important Caveats

  • As it stands (May 18, 2020), this is simply a notification service. There is no support for embedding custom actions (buttons, dialogs) regardless of platform. Other then telling you if the shell command was sent, there is also no confirmation on user action on the notification.
  • macOS does not support custom icons on the fly.. You will need to bundle a customized version of the notifier embedded with your custom icon.

Windows Specific:

  • No support for balloon tips (pre Win10).. This will be changed in the future.

GitHub:

https://github.com/ms7m/notify-py

Please comment and share this post and wants to improve this post WhatsApp us.

Default image
Lingaraj Senapati
Hey There! I am Lingaraj Senapati, the Co-founder of lingarajtechhub.com My skills are Freelance, Web Developer & Designer, Corporate Trainer, Digital Marketer & Youtuber.
Articles: 217

Newsletter Updates

Enter your email address below to subscribe to our newsletter

Leave a Reply