Ubuntu – How to send desktop notifications using Python 3


I have a python3.4 script.
I would like to send to the desktop a notification.
How do I handle this in python? Can I use notify-send?

I'm using Ubuntu 14.04.

#in my script
if something:
  notify-send 'Here is a notification !'

Best Answer

You can use notify-send as an external command:

import subprocess as s

Or you can use the notify2 module (sudo apt install python3-notify2):

import notify2
n = notify2.Notification('foo', 'bar')

There are more examples included in the package (see /usr/share/doc/python3-notify2/examples/).