Skip to main content

Python wrapper for the API Alerts service

Project description

API Alerts • Python Client

PyPI Python License: MIT

PyPIGitHubAPI Alerts

Effortless project notifications. Send once, deliver everywhere.

Installation

pip install apialerts

Quick Start

from apialerts import ApiAlerts, Event

ApiAlerts.configure('your-api-key')
ApiAlerts.send(Event(message='Deploy complete'))

Usage

Global singleton

Call configure once at startup, then use send / send_async anywhere.

from apialerts import ApiAlerts, Event

ApiAlerts.configure('your-api-key')

# Fire-and-forget. Never raises, silently drops errors.
# Pass debug=True to configure() to log them via stdlib logging.
ApiAlerts.send(Event(message='Deploy complete'))

# Or get the result back. Never raises, check result.success.
result = await ApiAlerts.send_async(Event(message='Deploy complete'))
if result.success:
    print(f'Sent to {result.workspace} ({result.channel})')
else:
    print(f'Error: {result.error}')

Enable debug logging

ApiAlerts.configure('your-api-key', debug=True)

The SDK uses Python's stdlib logging module under the logger name 'apialerts'. Critical errors (missing API key, not yet configured) always log via logger.error(...). Debug success/warning messages log via logger.info(...) and only fire when debug=True. Configure the apialerts logger to route output anywhere you like:

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

Event fields

Only message is required. All other fields are optional and omitted from the request body when not set.

from apialerts import Event

event = Event(
    message='Deploy complete',
    channel='releases',
    event='ci.deploy',
    title='Deployed',
    tags=['CI/CD', 'Python'],
    link='https://github.com/apialerts/apialerts-python/actions',
    data={'version': '1.2.0'},
)

result = await ApiAlerts.send_async(event)
Field Type Required Description
message str Yes Human-readable notification text. This is what appears on the push notification lock screen.
channel str No Workspace channel the push notification fires on. Defaults to the workspace default channel when omitted.
event str No Identifies what kind of thing happened. Optional but recommended. Use dotted notation (e.g. ci.deploy.success, payment.failed, user.signup) so routing rules can match glob patterns like ci.* or *.failed.
title str No Short headline some destinations render separately from the message body.
tags list[str] No Categorisation tags for filtering and search.
link str No URL associated with the event. Available as a deeplink for push notifications and as a call-to-action for routed destinations.
data dict[str, Any] No Arbitrary key-value metadata. Available to non-push destinations for templating (Slack message bodies, email templates, webhook payloads).

Send to multiple workspaces

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

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

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

API

Method Description
ApiAlerts.configure(api_key, debug=False) Initialise the singleton. First call wins; subsequent calls are no-ops.
ApiAlerts.send(event, api_key=None) Fire-and-forget. Never raises, drops errors silently unless debug is on.
ApiAlerts.send_async(event, api_key=None) Awaitable, returns SendResult. Never raises; check result.success.

SendResult fields

Field Type Description
success bool True if the alert was delivered
workspace str or None Workspace name (present on success)
channel str or None Channel name (present on success)
warnings list[str] Non-fatal warnings from the server
error str or None Error message (present on failure)

Links

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

apialerts-1.2.0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

apialerts-1.2.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file apialerts-1.2.0.tar.gz.

File metadata

  • Download URL: apialerts-1.2.0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for apialerts-1.2.0.tar.gz
Algorithm Hash digest
SHA256 bcd7e13c942bc41d9b91e45d7ba48eabac7a4302d5fcc6b655e9185ce91ab190
MD5 20a8f63194c0d78cabb52980d4fab43a
BLAKE2b-256 3e14b02044df465dd705d15f6e77acca85c6ebf6282507f39cb0942501a3e44b

See more details on using hashes here.

Provenance

The following attestation bundles were made for apialerts-1.2.0.tar.gz:

Publisher: publish-pypi.yml on apialerts/apialerts-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file apialerts-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: apialerts-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for apialerts-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c942863f8833b413d606d79c76f08f962804215da2bff4fc8fff3212643ec35a
MD5 5082c2587d35d1fb55a07bbae4b38423
BLAKE2b-256 acdf5e9a9840617e52203e5e9c39ce75b2631b91418e1f63e1c021fec70506a3

See more details on using hashes here.

Provenance

The following attestation bundles were made for apialerts-1.2.0-py3-none-any.whl:

Publisher: publish-pypi.yml on apialerts/apialerts-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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