notify2 - DBus Desktop Notifications

0.3.1 · maintenance · verified Fri Apr 17

notify2 is a Python interface to DBus notifications, allowing applications to send desktop notifications via the freedesktop.org Desktop Notifications Specification. It provides a simple API to initialize an application, create notifications with summaries, bodies, and icons, and control their display. The current version is 0.3.1, released in 2017. The project appears to be in maintenance mode, with no new feature development expected.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes `notify2`, creates a basic desktop notification with a summary, body, and icon, sets a timeout, and displays it. Requires a running DBus session and a notification daemon (e.g., dunst, xfce4-notifyd) on a Linux desktop environment.

import notify2
import os

# Initialize the notification system with your app name
# This is required before sending any notifications
notify2.init(os.environ.get('NOTIFY_APP_NAME', 'MyPythonApp'))

# Create a new notification
# Arguments: summary, body (optional), icon (optional)
n = notify2.Notification(
    "Hello from notify2!", 
    "This is a test notification generated by a Python script.",
    icon='dialog-information' # Example icon name (often from GTK/freedesktop theme)
)

# Set a timeout for the notification (in milliseconds)
# -1 means 'never expire' (if supported by daemon), 0 means 'default'
n.set_timeout(5000) # 5 seconds

# Show the notification
n.show()
print("Notification sent! Check your desktop.")

view raw JSON →