Cross-platform desktop notifier in Python Cross-platform desktop notifier in Python python python

Cross-platform desktop notifier in Python


Here's a desktop notifier I wrote a few years ago using wxPython - it behaves identically across Windows and Linux and should also run on OSX. It contains a threaded event loop that can be used to animate a notification window containing an icon and message that can be clicked on. It probably needs a couple of tweaks to customize it for your own purpose but the ground work is done.


At Pycon 2010 there was a presentation on cross-platform Python development.There was a html page about it as well, containing some advice for cross-platform notification. However, I don't find it online anymore, but I saved a local copy, and this is the part on notifications:

There are occasions in which your application wants to notify the userabout something: software updates are available, a new instant messagehave been received, the 300 page print job has finally finished, etc.

  • To keep notifications easy to port cross-platform, don't makethem interactive. For example Ubuntu does not support notificationsthat require user interaction.

  • These are the most important libraries:

    o Linux: pynotify.

    o Mac OS X: Growl, which is not standard, is usuallyinstalled.

    o Windows: a good wxPython solution is ToasterBox of AndreaGavana, which mimics the look of Firefox or Thunderbird notifications.

  • For Phatch we developed a library that unifies these threesystems in one API: phatch/lib/notify.py.

The linked python file is very interesting, and I think you should be able to use the linked python file almost as is. The code is also very clear, so you'll quickly see what it does.

The basic approach is it detects what notification systems are available, almost regardless of the platform, and tries to use them in a certain order but falls back to more simple systems if necessary. This way, if the user has e.g. Growl installed it'll use it, regardless of the platform.

You could adapt it to provide support for other notification systems than the three mentioned above.


  • How to go about writing it

    Check how keyring handles the cross-platform issues (it's a python library which plugs into various autodetected keychain backends for storage)

  • Growl isn't bundled with OSX you have to install it separately, OSX doesn't come with any built-in notification system.

  • For unixes, you might want to hook into DBus as already mentioned (as a fallback, note that dbus might also be available in OSX), but both KDE and Gnome have Growl-like libraries. Respectively, KNotification for KDE and libnotify for Gnome.

  • For windows, check out Snarl, fall back to notification bubbles if not available (using something along the lines of ToasterBox)

Do not ever even think of making notifications sticky. It's stupid, it's insensitive and it's freaking annoying. Also, due to people like you it's been made not available in most notification systems.

Finally, even if there is no Python lib for any of these, you can probably use ctypes to access them.