scitex_notification

SciTeX Notification Module - User alerts and feedback.

Usage:

import scitex_notification as stxn

# Simple alert - uses fallback priority (audio -> emacs -> desktop -> …) stxn.alert(“2FA required!”)

# Specify backend (no fallback) stxn.alert(“Error”, backend=”email”)

# Multiple backends (tries all) stxn.alert(“Critical”, backend=[“audio”, “email”])

# Use fallback explicitly stxn.alert(“Important”, fallback=True)

# Make a phone call via Twilio stxn.call(“Critical alert!”)

# Send an SMS via Twilio stxn.sms(“Build done!”)

Environment Variables:

SCITEX_NOTIFICATION_DEFAULT_BACKEND: audio, email, desktop, webhook SCITEX_NOTIFICATION_ENV_SRC: path to .env file to auto-load on import

scitex_notification.alert(message: str, title: str | None = None, backend: str | list[str] | None = None, level: str = 'info', fallback: bool = True, **kwargs) bool[source]

Send alert synchronously.

Parameters:
  • message (str) – Alert message

  • title (str, optional) – Alert title

  • backend (str or list[str], optional) – Backend(s) to use. If None, uses fallback priority order.

  • level (str) – Alert level: info, warning, error, critical

  • fallback (bool) – If True and backend fails, try next in priority order.

Returns:

  • bool – True if any backend succeeded

  • Fallback Order

  • ————–

  • 1. audio - TTS (fast, non-blocking)

  • 2. emacs - Minibuffer message

  • 3. matplotlib - Visual popup

  • 4. playwright - Browser popup

  • 5. email - Email (slowest)

async scitex_notification.alert_async(message: str, title: str | None = None, backend: str | list[str] | None = None, level: str = 'info', fallback: bool = True, **kwargs) bool[source]

Send alert asynchronously.

Parameters:
  • message (str) – Alert message

  • title (str, optional) – Alert title

  • backend (str or list[str], optional) – Backend(s) to use. If None, uses default with fallback.

  • level (str) – Alert level: info, warning, error, critical

  • fallback (bool) – If True and backend fails, try next in priority order. Default True when backend=None, False when backend specified.

Returns:

True if any backend succeeded

Return type:

bool

scitex_notification.available_backends() list[str][source]

Return list of available alert backends.

scitex_notification.call(message: str, title: str | None = None, level: str = 'info', to_number: str | None = None, **kwargs) bool[source]

Make a phone call via Twilio.

Convenience wrapper for alert(backend=”twilio”).

async scitex_notification.call_async(message: str, title: str | None = None, level: str = 'info', to_number: str | None = None, **kwargs) bool[source]

Make a phone call via Twilio (async).

scitex_notification.notify(subject: str = '', message: str = ':)', file: str | None = None, ID: str = 'auto', sender_name: str | None = None, recipient_email: str | None = None, cc: str | list | None = None, attachment_paths: list | None = None, verbose: bool = False) None[source]

Send a script-aware notification email.

Builds a subject/body from the calling script’s name and appends a footer with host, script, package version and git branch, then delegates to send_gmail().

Credentials and recipient are read from environment variables (with backward-compatible aliases):

  • sender: SCITEX_SCHOLAR_EMAIL_NOREPLY / SCITEX_SCHOLAR_FROM_EMAIL_ADDRESS / SCITEX_EMAIL_NOREPLY / SCITEX_EMAIL_AGENT (default no-reply@scitex.ai)

  • password: SCITEX_SCHOLAR_EMAIL_PASSWORD / SCITEX_SCHOLAR_FROM_EMAIL_PASSWORD / SCITEX_EMAIL_PASSWORD

  • recipient: SCITEX_SCHOLAR_EMAIL_RECIPIENT / SCITEX_SCHOLAR_TO_EMAIL_ADDRESS (or pass recipient_email=)

scitex_notification.send_gmail(sender_gmail: str, sender_password: str, recipient_email: str, subject: str, message: str, sender_name: str | None = None, cc: str | list | None = None, ID: str | None = None, attachment_paths: list | None = None, verbose: bool = True, smtp_server: str | None = None, smtp_port: int | None = None) None[source]

Send an email via SMTP.

Despite the name, supports any SMTP server. Uses mail1030.onamae.ne.jp by default (for scitex.ai emails) and falls back to Gmail’s server when the sender address ends in @gmail.com.

Parameters:
  • sender_gmail (str) – Sender email address (and SMTP login).

  • sender_password (str) – SMTP password.

  • recipient_email (str) – Primary recipient address.

  • subject (str) – Email subject. If ID is given it is appended as (ID: ...).

  • message (str) – Plain-text body.

  • sender_name (str, optional) – Display name for the From header.

  • cc (str or list, optional) – CC recipient(s).

  • ID (str, optional) – Message ID. Pass "auto" to auto-generate one.

  • attachment_paths (list, optional) – Paths of files to attach. .log files are ANSI-stripped.

  • verbose (bool) – Print a confirmation line on success.

  • smtp_server (optional) – Override SMTP host/port auto-detection.

  • smtp_port (optional) – Override SMTP host/port auto-detection.

scitex_notification.sms(message: str, title: str | None = None, to_number: str | None = None, **kwargs) bool[source]

Send an SMS via Twilio.

Parameters:
  • message (str) – SMS body text

  • title (str, optional) – Prepended to message if provided

  • to_number (str, optional) – Override SCITEX_NOTIFICATION_TWILIO_TO

Returns:

True if SMS sent successfully

Return type:

bool

async scitex_notification.sms_async(message: str, title: str | None = None, to_number: str | None = None, **kwargs) bool[source]

Send an SMS via Twilio (async).

Parameters:
  • message (str) – SMS body text

  • title (str, optional) – Prepended to message if provided

  • to_number (str, optional) – Override SCITEX_NOTIFICATION_TWILIO_TO

Returns:

True if SMS sent successfully

Return type:

bool