Skip to main content

Script and module for sending desktop notifications

Project description

A python script for sending desktop notifications from the shell.


Libnotify is part of many scripts in the Linux world. It utilizes many of the specified features of the Desktop Notifications Specification and makes them accessible to shell-scripts. It does not however allow to replace an existing notification with the replaces-id. This is a known bug since 2008 and has a patch since 2012. The patch is still not upstream though (2018).

This python script utilizes the notify2 package and exposes the functionality to the shell.

Differences between and notify-send

  • In -h shows help instead of being the parameter for hints. For hints use --hint.
  • In -r ID and --replaces-id ID exists. In order to replace a notification call with the ID that was returned by the notification to be replaced.
  • returns the ID of the newly created notification.
  • --replaces-process NAME exists. Every notification that gets created with the same NAME will replace every notification before it with the same NAME. If called with this parameter might block, best to be called with a trailing &.
  • -h has action-support (buttons). Try "Yes or no?" --action ok:OK cancel:Cancel


Requires python 3.

From PyPI:

pip install

From repo:

git clone
pip install .


$ -h
usage: [-h] [-u LEVEL] [-t TIME] [-a APP_NAME]
                      [-i ICON[,ICON...]] [-c TYPE[,TYPE...]]
                      [--hint [TYPE:NAME:VALUE [TYPE:NAME:VALUE ...]]]
                      [-r ID] [--replaces-process NAME]
                      [--action [KEY:NAME [KEY:NAME ...]]]
                      SUMMARY [BODY]

positional arguments:
  SUMMARY               Summary of the notification. Usage of \n and \t
                        is possible.
  BODY                  Body of the notification. Usage of \n and \t is

optional arguments:
  -h, --help            show this help message and exit
  -u LEVEL, --urgency LEVEL
                        Specifies the urgency level (low, normal,
  -t TIME, --expire-time TIME
                        Specifies the timeout in milliseconds at which
                        to expire the notification.
  -a APP_NAME, --app-name APP_NAME
                        Specifies the app name for the icon
  -i ICON[,ICON...], --icon ICON[,ICON...]
                        Specifies an icon filename or stock icon to
  -c TYPE[,TYPE...], --category TYPE[,TYPE...]
                        Specifies the notification category.
                        Specifies basic extra data to pass. Valid types
                        are int, double, string, boolean and byte.
  -r ID, --replaces-id ID
                        Specifies the id of the notification that should
                        be replaced.
  --replaces-process NAME
                        Specifies the name of a notification. Every
                        notification that gets created with the same
                        NAME will replace every notification before it
                        with the same NAME.
  --action [KEY:NAME [KEY:NAME ...]]
                        Specifies actions for the notification. The
                        action with the key "default" will be dispatched
                        on click of the notification. Key is the return
                        value, name is the display-name on the button.

notify-send[.py] as root user

In order to display notifications, even if libnotify or is used from the root user this script is helpful. You need to customize it with your username and userid (which probably is 1000 but can be found out by running cat /etc/passwd | grep <username>).

USERNAME=<your username here>

export XAUTHORITY=/home/$USERNAME/.Xauthority
export DISPLAY=:0
export DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USERID/bus

if [ "$(/usr/bin/id -u)" != "$USERID" ] ; then
    sudo -u $USERNAME XAUTHORITY=/home/$USERNAME/.Xauthority DISPLAY=:0 DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$USERID/bus /usr/bin/ "$@"
    /usr/bin/ "$@"

See also

Also take a look at my notification-daemon inspired by Dunst, but with several improvements, including the possibility of a transparent background and a notification center that stores notifications.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for, version 1.2.2
Filename, size File type Python version Upload date Hashes
Filename, size (6.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size (5.6 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page