Skip to main content

A Python package that automatically sends email notifications when functions fail

Project description

auto-alarm

A Python package that automatically sends email notifications when functions fail.

Features

  • Simple decorator-based API
  • Configurable via dictionary, JSON file, or environment variables
  • Support for multiple recipients
  • Optional success notifications
  • Full error traceback in email

Installation

pip install auto-alarm

Or install from source:

pip install -e .

Quick Start

from auto_alarm import init_notifier, notify_on_failure

# Initialize with SMTP settings
init_notifier(
    host='smtp.gmail.com',
    port=587,
    username='your_email@gmail.com',
    password='your_app_password',
    from_email='your_email@gmail.com'
)

# Use decorator to monitor function
@notify_on_failure('recipient@example.com')
def train_model(epochs):
    if epochs > 100:
        raise ValueError("Epochs cannot exceed 100")
    return f"Model trained for {epochs} epochs"

# Function fails - email will be sent automatically
result = train_model(150)

Configuration

Dictionary Configuration

from auto_alarm import init_notifier

init_notifier(
    host='smtp.gmail.com',
    port=587,
    username='your_email@gmail.com',
    password='your_app_password',
    from_email='your_email@gmail.com',
    use_tls=True  # default
)

JSON Configuration

// config.json
{
    "host": "smtp.gmail.com",
    "port": 587,
    "username": "your_email@gmail.com",
    "password": "your_app_password",
    "from_email": "your_email@gmail.com"
}
from auto_alarm import init_from_config

with open('config.json') as f:
    config = json.load(f)

init_from_config(config)

Environment Variables

Set these environment variables:

  • AUTO_ALARM_HOST
  • AUTO_ALARM_PORT
  • AUTO_ALARM_USERNAME
  • AUTO_ALARM_PASSWORD
  • AUTO_ALARM_FROM_EMAIL
from auto_alarm import init_from_config, Config

config = Config.from_env()
init_from_config(config)

API Reference

init_notifier(host, port, username, password, from_email, use_tls=True)

Initialize the global email notifier.

init_from_config(config)

Initialize from Config object or dictionary.

@notify_on_failure(to_emails, notify_on_success=False, success_message=None)

Decorator that sends email notification on function failure.

  • to_emails: Recipient email address(es) (str or list)
  • notify_on_success: Send notification on success (default: False)
  • success_message: Custom message for success notifications

SMTP Examples

Gmail

init_notifier(
    host='smtp.gmail.com',
    port=587,
    username='your_email@gmail.com',
    password='your_app_password',  # Use App Password, not your login password
    from_email='your_email@gmail.com'
)

Note: For Gmail, you need to enable 2-Step Verification and create an App Password.

Outlook

init_notifier(
    host='smtp.office365.com',
    port=587,
    username='your_email@outlook.com',
    password='your_password',
    from_email='your_email@outlook.com'
)

License

MIT

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

auto_alarm-0.1.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

auto_alarm-0.1.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file auto_alarm-0.1.0.tar.gz.

File metadata

  • Download URL: auto_alarm-0.1.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for auto_alarm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a76953e7943784cb8837ffb304234742787baa5acf0d6d856e1e0cc4d0e5c9a3
MD5 f2905c056c89d4de68589312958f999d
BLAKE2b-256 fa658422bd0a0d0a13d7a11d3452246d6abadb341b204cca9e42899f487a5511

See more details on using hashes here.

File details

Details for the file auto_alarm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: auto_alarm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for auto_alarm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ca0c7cd8f191da799d9ba5050fd03557236c2e4b24b5f14efdb4c058107db41
MD5 5890d10a5a500a43e5efae636846aff7
BLAKE2b-256 c518695783f35a6b18da9836460b8efb00732fd6329755d015356d86b130d0ef

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