Ansys Notifier#
The Ansys Notifier is a tool for sending notifications to various channels, such as email, Slack, Microsoft Teams, and more. It is built on top of the Apprise library, which provides a unified interface for sending notifications to multiple services.
To use the Ansys Notifier, you need to first install the optional dependencies.
pip install "ansys-tools-common[notifications]"
Once you have the dependencies installed, you can create an instance of the AnsysNotifier class and use it to include it into your code to send notifications. For example:
from ansys.tools.common.notifications import AnsysNotifier
notifier = AnsysNotifier()
notifier.notify("Hello, world!")
Or you can use the convenience function to send a notification without creating an instance:
from ansys.tools.common.notifications import notify
notify("Hello, world!")
In both cases, the notification is sent to the native desktop notification service for the current OS (Windows toast, macOS Notification Center, or Linux D-Bus) unless you specify channels explicitly.
Notification channels#
Use NotificationChannel members to select
well-known channels with IDE auto-complete support. Channels whose URLs require
credentials or IDs (such as Slack or email) are provided as scheme prefixes that you
concatenate with your specific tokens.
Member |
URL / prefix |
Notes |
|---|---|---|
|
|
Windows 10/11 native toast |
|
|
macOS Notification Center |
|
|
Linux desktop via D-Bus (GNOME, KDE, …) |
|
|
Gmail with App Password; append |
|
|
Corporate SMTP/TLS; append |
|
|
Slack; append |
|
|
Microsoft Teams webhook; append |
from ansys.tools.common.notifications import AnsysNotifier, NotificationChannel, notify
# Fixed channels — use the enum member directly
notifier = AnsysNotifier(channels=[NotificationChannel.WINDOWS])
# Parametrised channels — concatenate your credentials
notify(
"Job done.",
channels=[
NotificationChannel.SLACK + "mytoken/mychannel",
NotificationChannel.MAILTOS + "user:pass@smtp.company.com",
],
)
A plain str is always accepted, so existing code using raw URL strings continues
to work unchanged. For channels not listed above, pass a plain string with any URL
supported by Apprise. The full list of services is available at
https://appriseit.com/services/.
Global configuration#
Process-wide defaults can be set once, for example at app start-up,
so that every subsequent call to notify()
and notify_on_completion() picks them up
automatically without repeating the same arguments everywhere.
Four settings are available, each controlled by a getter/setter pair:
Setter / Getter |
Description |
|---|---|
|
Default channels used when no channels argument is passed. |
|
Default |
|
Whether a failure notification is sent when a decorated function raises
(initial value: |
|
Default |
from ansys.tools.common.notifications import (
set_notification_channels,
set_notification_level,
set_notify_on_failure,
set_failure_notification_level,
get_notification_channels,
get_notification_level,
NotificationChannel,
NotificationType,
notify,
notify_on_completion,
)
# Configure once at start-up
set_notification_channels([NotificationChannel.SLACK + "mytoken/mychannel"])
set_notification_level(NotificationType.SUCCESS)
set_notify_on_failure(True)
set_failure_notification_level(NotificationType.FAILURE)
# All subsequent calls use the defaults above — no need to repeat them
notify("Simulation complete.")
@notify_on_completion("Solve finished.")
def solve():
...
Per-call arguments always take priority over the global defaults, so individual calls can still override any setting when needed:
# Override the global channel for this call only
notify("Done.", channels=[NotificationChannel.WINDOWS])