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.
💡 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
ToastGenerictemplate 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-oscommands 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
-
Windows:
- Uses PowerShell to interface with the Windows Runtime (WinRT)
ToastGenericvisual 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_idto theToastNotification.Tagproperty 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).
- Uses PowerShell to interface with the Windows Runtime (WinRT)
-
macOS:
- Executes AppleScript (
osascript) with display notification instructions. - Implements robust escaping for double quotes and backslashes to eliminate script execution failures.
- Executes AppleScript (
-
Linux:
- Detects
DISPLAYandWAYLAND_DISPLAYenvironments. - If GUI is present, uses
notify-sendwith a progressive fallback array (peels off unsupported options like-ror-astep-by-step if the localnotify-sendversion is outdated). Falls back tozenity --notificationifnotify-sendis completely absent. - If headless (no GUI), automatically prints notification details to standard error (
sys.stderr) to prevent crashes.
- Detects
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file yyds_notify_os-0.2.0.tar.gz.
File metadata
- Download URL: yyds_notify_os-0.2.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a1bef46104f8c837c359e8da570abaed3fd4cbae41a218bb68753712d37429cd
|
|
| MD5 |
09c4100401d160dd9d63b0ae3a1a4b3a
|
|
| BLAKE2b-256 |
997aad5f354791fb32b9b906c7907c59cefe9230c50c815dcaede23a81a25bed
|
File details
Details for the file yyds_notify_os-0.2.0-py3-none-any.whl.
File metadata
- Download URL: yyds_notify_os-0.2.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c8140fa1a449b290dc4fabad695f054c551847e5ee9aa5a856db848dfca40b15
|
|
| MD5 |
061ea762fff5c7bf297fcd9f6b16acf2
|
|
| BLAKE2b-256 |
0d4fa3bd6212a33f36050acf826eb845f408dd355708da4f694b962408ed055d
|