How do I send desktop notifications using Python 3?

You can use notify-send as an external command:

import subprocess as s
s.call(['notify-send','foo','bar'])

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

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

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


No specific dependencies needed. These are wrappers around dbus anyway.

import dbus

bus_name = "org.freedesktop.Notifications"
object_path = "/org/freedesktop/Notifications"
interface = bus_name

notify = dbus.Interface(dbus.SessionBus().get_object(bus_name, object_path), interface)
notify.Notify(ARGS)

For the args see the specs.