Browse Docs

Python Alerts SDK

The API Alerts Python SDK sends alerts from your Python code through API Alerts. Drop it into Django, Flask, FastAPI, Celery workers, or any Python service that needs to notify you when something important happens. Minimal setup, fire-and-forget by default with optional response handling, and zero infrastructure.

Installation

pip install apialerts

Usage

from apialerts import ApiAlerts, Event

ApiAlerts.configure('YOUR-API-KEY')

# Simple notification
ApiAlerts.send(Event(message='Deployment successful'))

# With routing (recommended for production)
ApiAlerts.send(Event(event='ci.deploy.success', message='Deployment successful'))

# With all options
ApiAlerts.send(Event(
    event='user.signup',
    message='New user signed up',
    channel='developers',
    title='New Signup',
    tags=['signup', 'organic'],
    link='https://dashboard.example.com/users/123',
    data={'plan': 'pro', 'region': 'us-east-1'},
))

Event fields

FieldTypeRequiredDescription
messagestrYesHuman-readable notification text. This is what appears on the push notification lock screen.
channelstrNoWorkspace channel the push notification fires on. Defaults to the workspace default channel when omitted.
eventstrNoWhat kind of thing happened. Optional but recommended. Routers match this value with Unix glob (fnmatch): dotted keys like ci.deploy.success match ci.*, and free-form keys like User Signup match User *. Dotted notation is just a tidy convention, not a requirement.
titlestrNoShort headline some destinations render separately from the message body.
tagslist[str]NoCategorisation tags for filtering and search.
linkstrNoURL associated with the event. Available as a deeplink for push notifications and as a call-to-action for routed destinations.
datadict[str, Any]NoArbitrary key-value metadata. Available to non-push destinations for templating (Slack message bodies, email templates, webhook payloads).

Optional fields are omitted from the request body when None - they’re never sent as null.

Wait for the response

send is fire-and-forget and never raises. For a result you can inspect, use send_async. It never raises either - check result.success.

result = await ApiAlerts.send_async(Event(message='Deployment successful'))
if not result.success:
    print(f'Error: {result.error}')
else:
    print(f'Sent to {result.workspace} ({result.channel})')

The SendResult shape:

@dataclass
class SendResult:
    success: bool
    workspace: Optional[str]   # populated on success
    channel: Optional[str]     # populated on success
    warnings: list[str]        # non-fatal server warnings
    error: Optional[str]       # populated on failure

Send to multiple workspaces

Pass an api_key as the optional second argument to override the configured key for a single call.

ApiAlerts.send(Event(message='Deploy complete'), api_key='other-workspace-api-key')

Debug logging

Pass debug=True to configure to log success, warning, and error events via the stdlib logging module under the 'apialerts' logger.

ApiAlerts.configure('YOUR-API-KEY', debug=True)

import logging
logging.getLogger('apialerts').setLevel(logging.INFO)
logging.basicConfig()

Critical errors (missing API key, not yet configured) always log regardless of the debug flag.

Resources