How do I send text messages to the notification bubbles?

We can always call notify-send as a subprocess, e.g like that:

#!/usr/bin/env python
#-*- coding: utf-8 -*-

import subprocess

def sendmessage(message):
    subprocess.Popen(['notify-send', message])
    return

Alternatively we could also install python-notify2 or python3-notify2 and call the notification through that:

import notify2

def sendmessage(title, message):
    notify2.init("Test")
    notice = notify2.Notification(title, message)
    notice.show()
    return

python3

Whilst you can call notify-send via os.system or subprocess it is arguably more consistent with GTK3 based programming to use the Notify gobject-introspection class.

A small example will show this in action:

from gi.repository import GObject
from gi.repository import Notify

class MyClass(GObject.Object):
    def __init__(self):

        super(MyClass, self).__init__()
        # lets initialise with the application name
        Notify.init("myapp_name")

    def send_notification(self, title, text, file_path_to_icon=""):

        n = Notify.Notification.new(title, text, file_path_to_icon)
        n.show()

my = MyClass()
my.send_notification("this is a title", "this is some text")

You should use notify2 package, it is a replacement for python-notify. Use it as followed.

pip install notify2

And the code:

import notify2
notify2.init('app name')
n = notify2.Notification('title', 'message')
n.show()