Skip to main content

Portable Discord webhook notification transport with severity routing, 429 backoff, and audit mirror. Zero runtime dependencies.

Project description

discord-alert-transport

License: MIT Python 3.10+ Zero dependencies Docs

Portable Discord webhook transport. One Python package, ten language references. From "hello world" to severity-routed phone alerts in 3 minutes.

📖 Full documentation: https://jdp5949.github.io/discord-alert-transport/


What this is

A Discord webhook is a public URL that turns any HTTP POST into a Discord channel message. No bot. No OAuth. No SDK strictly required.

This repo gives you:

  1. A Python package with production batteries — severity routing, 429 Retry-After backoff, audit-channel mirror, secret-safe logging.
  2. 10 language reference implementations (Python, JS, TS, Go, Rust, Bash, PHP, Ruby, Java, C#) — same protocol, your stack.
  3. Production patterns documented — throttling, dedup, secret hygiene, test-suite guards, mobile push setup.

Why

Problem Discord webhook solves it
Push alerts on my phone, free yes
Different channels per severity yes
Unlimited free message history yes
Colour-coded triage yes (embeds)
Threaded postmortems attached to alerts yes (Discord threads)
Don't want to build a dashboard yes
Don't want to pay for PagerDuty / Opsgenie yes
Use from any language yes (HTTP POST)

Install (Python)

pip install git+https://github.com/jdp5949/discord-alert-transport

(PyPI release pending — for now install from git.)

Requirements: Python 3.10+. Zero runtime dependencies.

Hello, world

from discord_alert_transport import Channel, DiscordSender, build_embed

s = DiscordSender(
    webhooks={Channel.ALERTS: "https://discord.com/api/webhooks/.../..."},
    enabled=True,
)
s.send_embed(
    Channel.ALERTS,
    build_embed(title="Hello", description="From discord-alert-transport", color=0x00cc66),
)

Phone buzzes.

Hello, world (other languages)

bash + curl

curl -X POST -H "Content-Type: application/json" \
  -d '{"content":"hello from bash"}' "$DISCORD_WEBHOOK"

Node.js

await fetch(process.env.DISCORD_WEBHOOK, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ content: 'hello from node' }),
});

Go

http.Post(os.Getenv("DISCORD_WEBHOOK"), "application/json",
    strings.NewReader(`{"content":"hello from go"}`))

See examples/ for full versions with 429 backoff in 10 languages.

Five-channel severity layout (convention)

Channel Severity Embed colour
#alerts P0 / P1 red / orange
#info P2 / P3 yellow / green
#trades P3 positive event blue
#dev DEV gray
#audit mirror of all events white
from discord_alert_transport import Severity, channel_for, color_for

notify(Severity.P0, "DB down", "Primary unreachable")
notify(Severity.P2, "Cache miss spike", "Hit rate dipped to 60%")

Full guide: Severity routing.

Features

  • Stdlib only (urllib.request). No requests, no httpx.
  • 429 Retry-After backoff — Discord rate-limits at ~5 req/sec/webhook.
  • Audit mirror — every send fans a one-liner to a dedicated audit channel for searchable history.
  • Secret-safe__repr__ and log records never include webhook URLs.
  • Failure-silent — never raises to caller; logs a warning and returns False.
  • Length limits enforcedbuild_embed truncates to Discord per-field maxes.
  • Configurable — bring your own channel keys, mention defaults, retry counts, timeouts.
  • Backwards-compatible string channel keys — pass enum members or raw strings.

Layout

src/discord_alert_transport/
    __init__.py          public API
    channels.py          Channel + Severity enums + routing helpers
    embed.py             length-safe embed builder
    sender.py            HTTP transport with 429 backoff + audit mirror
examples/
    python/              full-feature samples
    javascript/          Node 18+ fetch
    typescript/          typed fetch
    go/                  stdlib net/http
    rust/                reqwest + tokio
    bash/                curl
    php/                 stdlib curl
    ruby/                stdlib net/http
    java/                stdlib java.net.http
    csharp/              .NET HttpClient
tests/                   pytest suite (30+ tests)
docs/                    GitHub Pages site source

Tests

pip install -e .[dev]
pytest

Documentation site

Full hosted documentation, including use cases, production patterns, and the underlying webhook protocol: https://jdp5949.github.io/discord-alert-transport/

Use cases

25+ documented in use cases. Highlights:

  • CI/CD pass/fail notifications
  • Cron job monitoring
  • Prometheus/Grafana alerts
  • Backup completion
  • Application errors (with throttle/dedup)
  • Payment / Stripe webhook relay
  • New signup / churn alerts
  • IoT sensor alerts (temperature, leak, door)
  • Trading / fintech (fills, P&L, risk breaches — this package was extracted from one such system)
  • Security alerts (failed logins, new IP)
  • ChatOps approvals

Licence

MIT. See LICENSE.

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

discord_alert_transport-0.1.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

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

discord_alert_transport-0.1.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for discord_alert_transport-0.1.0.tar.gz
Algorithm Hash digest
SHA256 309425e67133d8bf9632c7acb8d1557469e9023a0d4101ed2acbf1ef4af6e20b
MD5 aadf9f8ca10c0bc89054fd280dcc0678
BLAKE2b-256 e867b5e15e2775601d155ec26bbfd9e064f49b36b1533982ce61932138256074

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for discord_alert_transport-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70528d35b9430bf96d0aaf7b7914e0343750d483f76b4d12788ce2f04252c8c2
MD5 2d5713a50e65a863ff35fce8a786a40e
BLAKE2b-256 09f655b79b7f42e77c633222283f3a0fae18436b1eabb93b0108de70edb28ed8

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