Skip to main content

Python library for cross-platform desktop notifications

Project description

Desktop Notifier

desktop-notifier is a Python library for cross-platform desktop notifications. Currently supported platforms are:

  • Linux via the dbus service org.freedesktop.Notifications
  • macOS via the Notification Center framework

Features

  • Clickable notifications (requires platform support)
  • Notifications with buttons (requires platform support)
  • Asyncio integration to execute callbacks on user interaction
  • Limit maximum number of notification shown for any app
  • Pure Python dependencies only, no extension modules

Installtion

From PyPI:

pip3 install -U desktop-notifier

Usage

Basic usage only requires the user to specify a notification title and message:

from desktop_notifier import DesktopNotifier

notifier = DesktopNotifier()
notifier.send(title="Hello world!", message="Notification body")

By default, "Python" will be used as the app name for all notification. Advanced usage allows specifying the app name, notification urgency, app icon, buttons and callbacks:

from desktop_notifier import DesktopNotifier, NotificationLevel

notifier = DesktopNotifier(app_name="Sample App")
notifier.send(
    title="Hello from Python!",
    message="A horrible exception occured",
    urgency=NotificationLevel.Critical,
    icon="/path/to/icon.png",
    action=lambda: print("notification clicked"),
    buttons={
        "Button 1": lambda: print("Button 1 clicked"),
        "Button 2": lambda: print("Button 2 clicked")
    },
)

Note that some platforms may not support all options. For instance, some Linux Desktop environments may not support notifications with buttons. On macOS, the app icon and name are always set to the application which calls the code. This will be Python when used interactively or any app name when run from a frozen and signed app bundle. Any options or configurations which are not supported by the platform will be silently ignored.

Execution of callbacks requires a running event loop. On Linux, it requires a running asyncio loop and on macOS it requires a running CFRunLoop. You can use rubicon-objc to integrate a Core Foundation CFRunLoop with asyncio:

import asyncio
from rubicon.objc.eventloop import EventLoopPolicy

# Install the event loop policy
asyncio.set_event_loop_policy(EventLoopPolicy())

# Get an event loop, and run it!
loop = asyncio.get_event_loop()
loop.run_forever()

Full documentation can be found at https://rubicon-objc.readthedocs.io/en/latest/how-to/async.html.

Notes on macOS

On macOS 10.14 and higher, the implementation uses the UNUserNotificationCenter instead of the deprecated NSUserNotificationCenter. UNUserNotificationCenter restricts sending desktop notifications to signed frameworks or app bundles. This means that notifications will only work if Python has been installed as a Framework and properly signed. This is the case when using the installer from python.org but not for homebrew installations.

If you are planning to use this library in an app bundle, you must sign the app bundle to send notifications, either with an Apple Developer certificate or ad-hoc for local usage.

Requirements

  • macOS 10.13 or higher
  • Linux desktop environment providing a dbus desktop notifications service

Dependencies

Project details


Download files

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

Source Distribution

desktop-notifier-1.0.0.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

desktop_notifier-1.0.0-py2.py3-none-any.whl (12.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file desktop-notifier-1.0.0.tar.gz.

File metadata

  • Download URL: desktop-notifier-1.0.0.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for desktop-notifier-1.0.0.tar.gz
Algorithm Hash digest
SHA256 fcc4e8db112a3d4b96b68d96cd03c6fe268585853fe9c3b9bd71c428c79aff53
MD5 e5e8745d6a024c0e0ca0092c61cf4aa6
BLAKE2b-256 4a770a1cf6e67182dc42c4b87fcbb8d027f7e63e74a8701b5cd87ada3ae0bed8

See more details on using hashes here.

File details

Details for the file desktop_notifier-1.0.0-py2.py3-none-any.whl.

File metadata

  • Download URL: desktop_notifier-1.0.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.7

File hashes

Hashes for desktop_notifier-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2d0f7488435df7d5e032cf448f4161e7c71a0ce9b0472fe59b136ebb238a7a91
MD5 0c9481251f9511de04d70cbe8b4f5067
BLAKE2b-256 ff847ce3af36f97d45f624dcdb18aef5077b74cecd20d9935e998b824bf0d4b2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page