AnsysNotifier#

class ansys.tools.common.notifications.AnsysNotifier(channels: list[NotificationChannel | str] | None = None, title: str = 'PyAnsys', format: NotificationFormat = NotificationFormat.TEXT, notification_type: NotificationType = NotificationType.INFO)#

Desktop and multi-channel notifier for PyAnsys job-completion events.

AnsysNotifier wraps apprise to provide a unified notification API across 100+ channels including native desktop toast notifications (Windows, macOS, Linux) and external services such as email, Slack, Microsoft Teams, and Telegram.

Parameters#

channelslist[NotificationChannel | str] | None, optional

List of apprise-compatible channel URLs. When None or empty the native desktop notification service for the current OS is used automatically (Windows toast, macOS Notification Center, Linux D-Bus).

Use NotificationChannel members for the common schemes, or pass a plain str for any URL supported by apprise:

NotificationChannel.WINDOWS  # Windows 10/11 toast
NotificationChannel.DBUS  # Linux (GNOME / KDE)
NotificationChannel.MACOS  # macOS Notification Center
NotificationChannel.MAILTO + "user:pass@gmail.com"  # Gmail
NotificationChannel.MAILTOS + "user:pass@smtp.corp.com"  # SMTP/TLS
NotificationChannel.SLACK + "token/channel"  # Slack
NotificationChannel.MSTEAMS + "A/B/C/D"  # MS Teams
"tgram://bot_token/chat_id"  # Telegram (plain str)

See https://appriseit.com/ for the full list.

titlestr, optional

Default notification title, by default "PyAnsys".

formatNotificationFormat, optional

Default body format, by default NotificationFormat.TEXT.

notification_typeNotificationType, optional

Default notification_type level, by default NotificationType.INFO.

Examples#

Standalone one-liner (desktop notification, auto-detected OS):

>>> notifier = AnsysNotifier()
>>> notifier.notify("Simulation complete.")

Integration inside a PyAnsys library, with a product-specific title and a success notification_type:

>>> from ansys.tools.common.notifications import AnsysNotifier, NotificationType
>>> _notifier = AnsysNotifier(title="PyMAPDL", notification_type=NotificationType.SUCCESS)
>>> _notifier.notify("Solve finished in 42 iterations.")

Multi-channel (desktop + email):

>>> notifier = AnsysNotifier(
...     channels=[NotificationChannel.WINDOWS, NotificationChannel.MAILTOS + "user:pass@smtp.company.com"]
... )
>>> notifier.notify("Job converged.")

HTML-formatted notification:

>>> from ansys.tools.common.notifications import NotificationFormat
>>> notifier = AnsysNotifier(format=NotificationFormat.HTML)
>>> notifier.notify("Residual: 1.23e-6 — converged.")

Overview#

add_channel

Add a notification channel.

notify

Send a notification to all registered channels.

title

Default title applied to all notifications from this instance.

format

Default body format applied to all notifications from this instance.

notification_type

Default notification_type applied to all notifications from this instance.

Import detail#

from ansys.tools.common.notifications import AnsysNotifier

Property detail#

property AnsysNotifier.title: str#

Default title applied to all notifications from this instance.

property AnsysNotifier.format: NotificationFormat#

Default body format applied to all notifications from this instance.

property AnsysNotifier.notification_type: NotificationType#

Default notification_type applied to all notifications from this instance.

Method detail#

AnsysNotifier.add_channel(url: str) bool#

Add a notification channel.

Parameters#

urlstr

An apprise-compatible notification URL.

Returns#

bool

True if the channel was accepted, False if the URL was invalid or a required backend library is not installed.

Examples#

>>> notifier = AnsysNotifier(channels=[])
>>> notifier.add_channel(NotificationChannel.SLACK + "token/channel")
True
AnsysNotifier.notify(message: str, title: str | None = None, format: NotificationFormat | None = None, notification_type: NotificationType | None = None) bool#

Send a notification to all registered channels.

Parameters#

messagestr

Body of the notification.

titlestr | None, optional

Overrides the instance-level title for this call only.

formatNotificationFormat | None, optional

Overrides the instance-level format for this call only.

notification_typeNotificationType | None, optional

Overrides the instance-level notification_type for this call only.

Returns#

bool

True if every channel accepted the notification, False if at least one channel failed.

Examples#

Basic informational notification:

>>> notifier.notify("Solve complete.")

Failure notification with a per-call notification_type override:

>>> notifier.notify("Divergence detected.", notification_type=NotificationType.FAILURE)

Success notification with a per-call title override:

>>> notifier.notify("Converged in 42 steps.", title="MyApp", notification_type=NotificationType.SUCCESS)