Skip to main content

A high-performance, lightweight, and easy-to-use cross-platform desktop notification library for Python.

Project description

yyds-notify-os

A high-performance, lightweight, and easy-to-use cross-platform desktop notification library for Python.

中文说明 (Chinese README)


💡 Key Features

  • Zero External Dependencies: Implemented strictly using the Python standard library. It interacts with native OS notification tools via subprocesses.
  • Microsecond-Level Startup: Highly optimized imports (under 1ms), leaving virtually zero performance footprint.
  • Non-blocking by Default: Notifications are dispatched asynchronously in background daemon threads, keeping your application GUI or CLI completely lag-free.
  • Notification Replacement/Updating (replace_id): Update an existing notification card in-place (ideal for progress bars or dynamic alerts) without cluttering the Action Center.
  • Modern Windows Customizations: Uses Microsoft's modern ToastGeneric template to support custom application icons (icon) and mapped system sounds (sound) or mute configurations.
  • Path Auto-Resolution: Automatically converts relative icon paths to absolute paths to prevent subprocess path resolution failures.
  • Robust Fail-Safe Fallbacks: Under headless environments (e.g. SSH sessions) or when graphical notifications fail, it gracefully falls back to console stderr output without crashing.
  • Command Line Interface (CLI): Out-of-the-box yyds-notify / yyds-notify-os commands for shell script integrations.

🚀 Installation

pip install -U yyds-notify-os

Or install from source in editable mode for local development:

pip install -e .

💻 Python API Usage

import yyds_notify_os as notify
import time

# 1. Simple Usage (Non-blocking by default)
notify.send("Task Complete", "Your compilation has finished successfully!")

# 2. Dynamic Update/Replacement (Same ID updates the same card in-place)
for i in range(1, 6):
    notify.send("Downloading", f"Progress: {i*20}%", replace_id="download_task_1")
    time.sleep(1)

# 3. Synchronous Blocking Call (Returns True/False based on execution success)
success = notify.send("Server Alert", "CPU temperature is too high!", urgency="critical", block=True)

# 4. Custom Cross-Platform Configuration
notify.send(
    title="Meeting Reminder",
    message="Technical review starts at 2:00 PM",
    subtitle="Sprint Sync",       # Supported on macOS and Linux-zenity
    icon="assets/bell.png",       # Automatically converted to absolute path (Windows/Linux)
    sound="sms",                  # Windows SMS tone mapping, default sound on macOS
    urgency="normal",             # Linux urgency levels: 'low', 'normal', 'critical'
    timeout=5,                    # Display timeout in seconds (Linux)
    app_name="yyds-notify"        # Custom application sender name (Windows/Linux)
)

Windows Built-in Sound Mappings (sound parameter)

  • "default": Default system sound
  • "im": Instant message sound
  • "mail": Email notification sound
  • "reminder": Calendar reminder sound
  • "sms": SMS/Text message sound
  • "alarm": Looping alarm sound
  • "call": Looping ringtone sound

API Aliases

The following functions are identical aliases for convenience:

  • yyds_notify_os.notify(...)
  • yyds_notify_os.send(...)
  • yyds_notify_os.show(...)

🛠️ CLI Usage

Once installed, send system notifications directly from your shell:

# Basic notification
yyds-notify "Notification" "Your build is ready!"

# Specify custom sender name
yyds-notify "Alert" "High memory usage detected!" -a "SystemMonitor"

# Dynamic notification updates using replace-id
yyds-notify "Build Status" "Compiling Module A..." -r "build_job_12"
yyds-notify "Build Status" "Compiling Module B..." -r "build_job_12"

# Complex call with sound and critical urgency
yyds-notify "Error" "Deployment failed!" -s "CI Pipeline" -u critical --sound

# View full help menu
yyds-notify --help

🛡️ Technical Implementation Details

  1. Windows:

    • Uses PowerShell to interface with the Windows Runtime (WinRT) ToastGeneric visual template.
    • All string arguments (title, message, icon path) are passed via process environment variables to completely avoid shell injection and encoding/truncation issues (e.g. UTF-8/GBK encoding clashes).
    • Maps replace_id to the ToastNotification.Tag property for in-place card updates.
    • Gracefully attempts to initialize the ToastNotifier with your custom app_name. If it fails (due to unregistered AppUserModelId on older Windows releases), it falls back to a guaranteed registered PowerShell AppID.
    • If WinRT initialization fails, it falls back to the classic balloon tip (System.Windows.Forms.NotifyIcon).
  2. macOS:

    • Executes AppleScript (osascript) with display notification instructions.
    • Implements robust escaping for double quotes and backslashes to eliminate script execution failures.
  3. Linux:

    • Detects DISPLAY and WAYLAND_DISPLAY environments.
    • If GUI is present, uses notify-send with a progressive fallback array (peels off unsupported options like -r or -a step-by-step if the local notify-send version is outdated). Falls back to zenity --notification if notify-send is completely absent.
    • If headless (no GUI), automatically prints notification details to standard error (sys.stderr) to prevent crashes.

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

yyds_notify_os-0.2.1.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

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

yyds_notify_os-0.2.1-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file yyds_notify_os-0.2.1.tar.gz.

File metadata

  • Download URL: yyds_notify_os-0.2.1.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for yyds_notify_os-0.2.1.tar.gz
Algorithm Hash digest
SHA256 18d4303a2929051994489232de47a05462fbf479945c14ecba6f922a36e63a7e
MD5 915637d8b68795d17fde8d5f99b580c4
BLAKE2b-256 43b26b881eeaf9d319c4e53a74b6ce0f79270b62a2478c0d2955cd362218d82a

See more details on using hashes here.

File details

Details for the file yyds_notify_os-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: yyds_notify_os-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 10.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for yyds_notify_os-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a64dcf62bfb042c94e6888aec2f6da3e07049293c1211bf394dca12664ad9039
MD5 b6ce505c46001240b7179870dfbfff4e
BLAKE2b-256 9b3aa4458ee2502ac9a270d4b587b5a413806e1a9ee0c060e174ae9fcea33958

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