Skip to main content

Lean Discord notification service for business events

Project description

Hibiki Discord

A lean Discord notification service for business events. Define notification types in a TOML config file, store webhook URLs in environment variables, and send notifications with one function call.

Python 3.11+ License: MIT GitHub

Installation

pip install hibiki-discord

Quick start

1. Create a config file (hibiki-discord.toml in your project root):

[notifications.user_signup]
webhook_url_env = "SIGNUP_DISCORD_WEBHOOK_URL"
username = "Signup Bot"
message_template = "New user signed up: {email}"

[notifications.subscription]
webhook_url_env = "SUBSCRIPTION_DISCORD_WEBHOOK_URL"
username = "Billing Bot"
message_template = "New {plan} subscription by {email}"

webhook_url_env is the name of the environment variable that holds the webhook URL. The TOML file contains no secrets and is safe to commit.

2. Set your webhook URLs as environment variables (e.g. in your .env file or deployment config):

  • SIGNUP_DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...
  • SUBSCRIPTION_DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/...

3. Send notifications:

from hibiki_discord import load_config, send_notification, fire_notification

load_config()  # reads hibiki-discord.toml

# Await the result (blocks the caller until sent)
await send_notification("user_signup", email="jane@example.com")

# Fire-and-forget (returns immediately, sends in the background)
fire_notification("subscription", plan="Pro", email="jane@example.com")

Emails are automatically anonymized in messages (e.g. j***@example.com).

Configuration

TOML config file

Each [notifications.<name>] section defines a notification type:

Key Required Default Description
webhook_url_env Yes - Name of the env var holding the Discord webhook URL
message_template Yes - Python format string for the message
username No - Display name for the Discord bot
enabled No true Set to false to disable this notification type

Config file location

By default, load_config() looks for hibiki-discord.toml in the current working directory. Override with:

  • Pass a path: load_config("/path/to/config.toml")
  • Set the HIBIKI_DISCORD_CONFIG env var: export HIBIKI_DISCORD_CONFIG=/path/to/config.toml

Programmatic configuration

Skip the TOML file and configure in Python:

from hibiki_discord.config import load_config_from_dict

load_config_from_dict({
    "user_signup": {
        "webhook_url_env": "DISCORD_SIGNUP_WEBHOOK",
        "username": "Signup Bot",
        "message_template": "New user: {email}",
    },
})

API reference

load_config(path=None) -> dict

Load notification config from a TOML file. Returns a dict of notification type name to config.

send_notification(notification_type, **template_vars) -> bool

Send a notification. Looks up the config, resolves the webhook URL from env, formats the template, and sends. Returns True on success. Raises ValueError if the type is unknown or the template is missing.

fire_notification(notification_type, **template_vars) -> asyncio.Task[bool]

Fire-and-forget variant of send_notification. Schedules the notification as a background task on the running event loop and returns immediately. Errors are logged instead of raised. The returned asyncio.Task can be awaited if you need the result, or simply ignored.

send(webhook_url, message, username=None) -> bool

Low-level send. Posts a message directly to a Discord webhook URL.

get_notification_config(notification_type) -> NotificationConfig | None

Get the config for a specific notification type, or None if not configured.

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

hibiki_discord-1.0.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

hibiki_discord-1.0.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file hibiki_discord-1.0.0.tar.gz.

File metadata

  • Download URL: hibiki_discord-1.0.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for hibiki_discord-1.0.0.tar.gz
Algorithm Hash digest
SHA256 4d5bed1e71cdd8d7fb920e6c618bd63b0364e3b76bc106dc9235bd71bce198ea
MD5 b0559da309fdde8528b6359b8b153dd8
BLAKE2b-256 a7fe59fb5463ae62270a4f08f3b15d76ff51009c18a87e8e00002c8c1596e140

See more details on using hashes here.

File details

Details for the file hibiki_discord-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: hibiki_discord-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for hibiki_discord-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 371f4be8d2561ae3151ba53e1c417eddc678af6de2b97d515dbdae391277799c
MD5 2e2340226d228186b08870ebf1e9ef58
BLAKE2b-256 c04ee0e9014fbba9c103c9528f33135d41a6a51895b5020eb4cab26a0e6bc6e3

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