Skip to main content

notification-py

notification-py is a Python package that provides a simple and convenient way to send notifications to Discord, Slack, MS Teams, and Email. You can send notification to either of these using a single command.

  • Total Downloads: Downloads
  • Monthly Downloads: Downloads

Motivation

Lately I noticed several critical errors poping up in my python backend, I thought of a simple way to get notified about these failues (be it Stripe webhooks or anything else). So I came up with this idea to create a simple notification package which can be imported and used when unexpected errors are thrown by code.

Using this package, developers can receive notifications through various combinations of Discord, Slack, MS Teams, and Email. The package supports sending notifications to all platforms simultaneously, any combination of them, or just one platform, depending on the provided credentials and configuration. This flexibility allows developers to customize their notification setup based on their specific requirements and preferences.

How to install?

To install notification-py using pip:

pip install notification-py

Usage

1. Importing types

To use notification-py in your Python project, you can import the send_notification function from the package. :

from notification_py.custom_types import (
    DiscordCreds,
    Message,
    Creds,
    EmailCreds,
    MessageDetails,
    SlackCreds,
    TeamsCreds,
)       

2. Creating Message Object:

Message object is core to the functionality of the notification-py package.

filename and line_number are optional — you can send generic notifications (e.g. "Customer onboarded") without them, not just code error alerts.

message = Message(
    message_details=MessageDetails(
        title="Test Title",
        text="Test Text",
        severity=2,
        source="Test Source",
        filename="Test Filename",
        line_number=0,
        time=datetime.now(),
    ),
    creds=Creds(
        discord=DiscordCreds(
            token="your_discord_bot_token",
            channel_id=your_discord_channel_id,
            team_id=your_discord_team_id,
        ),
        slack=SlackCreds(webhook_url="your_slack_webhook_url"),
        teams=TeamsCreds(webhook_url="your_teams_webhook_url"),
        email=EmailCreds(
            email="your_email",
            password="your_email_password",
            smtp_server="your_smtp_server",
            smtp_port=your_smtp_port,
            target_email="target_email",
        ),
    ),
)

The Message object consists of two main parts:

  1. message_details: An instance of MessageDetails that contains the details of the notification message, such as the title, text, severity, source, and timestamp. filename and line_number are optional.
  2. creds: An instance of Creds that holds the credentials for Discord, Slack, MS Teams, and email notifications.

These creds are independent of each other and one can just send Discord notifications using this message object (same applies for other combinations of these):

message = Message(
    message_details=MessageDetails(
        title="Customer Onboarded",
        text="Acme Corp has been successfully onboarded.",
        severity=0,
        source="CRM System",
        time=datetime.now(),
    ),
    creds=Creds(
        discord=DiscordCreds(
            token="your_discord_bot_token",
            channel_id=your_discord_channel_id,
            team_id=your_discord_team_id,
        ),
    ),
)

3. Sending notification:

You can just call this async function notify to send notification to all the services at a go.

from notification_py.main import send_notification

async def notify(message):
    await send_notification(message)

Please note that only those services which have valid creds will be notified.

Creating Credentials

To send notifications to Discord, Slack, and email, you need to provide the necessary credentials. Here's how you can create the credential objects:

1. Discord:

  1. You can obtain your Discord bot token by simply following this tutorial.
  2. Once you have the token and the bot is installed on your Discord server, just get your channel id and id of the role that you want to notify for the notification.

2. Slack:

  1. Go to Slack Apps and click Create New App.
  2. Choose From scratch, give it a name, and select your workspace.
  3. In the app settings, go to Incoming Webhooks (under Features) and toggle it On.
  4. Click Add New Webhook to Workspace, select the channel you want to post to, and click Allow.
  5. Copy the generated webhook URL — that's your webhook_url.

3. MS Teams:

  1. In Microsoft Teams, go to the channel where you want to receive notifications.
  2. Click More options (...) next to the channel and select Workflows.
  3. Search for and select the Post to a channel when a webhook request is received template.
  4. Configure the workflow parameters and click Save.
  5. Copy the generated webhook URL — that's your webhook_url.

For more details, see Send messages in Teams using incoming webhooks.

4. Email (for gmail):

  1. Make sure you have 2FA enabled.
  2. Just follow along this discussion to get your app password
  3. Once that is done, save the generated password and create email creds like this:
email = "YOUR_ID@gmail.com"
password = "GENERATED_APP_PASSWORD"
smtp_server = "smtp.gmail.com"
smtp_port = "587"
target_email = "RECIPIENT_ID@gmail.com"

Sample notifications

1. Discord

Sample Discord Notifications

2. Slack

Sample Slack Notifications

3. Email

Sample Email Notifications

Contact me

To raise any issues/requests you may refer the issue page here.

You may mail me here on my mail id.

Feel free to connect with me on my LinkedIn.

Please do check out my other projects on my GitHub here.

Also I have made many cool Firefox Add ons. They are pretty useful, you may want to check them out here.

If you like my work, you may want to buy me a book here.

Metadata

Release files for notification_py 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for notification_py 1.1.0
File Size Uploaded
notification_py-1.1.0.tar.gz 13.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for notification_py 1.1.0
File Interpreter ABI Platform
notification_py-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.4 kB

Release files / notification_py-1.1.0.tar.gz

Download URL notification_py-1.1.0.tar.gz
Size 13.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4f0d4f3a60397983b800dd58ed6c983c218d1621a499ca4df4c9d06328892297
BLAKE2b-256 checksum
How to use checksums
bbfadcb6e05473c8bdd8a9f400405f284832afe43be207fd2de0bc8fae105261
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.3 CPython/3.14.7 Darwin/25.6.0

Release files / notification_py-1.1.0-py3-none-any.whl

Download URL notification_py-1.1.0-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ebf8e11fea44d1ce2eabff277f566755b6e6cf033959924bc79d80a0315c725a
BLAKE2b-256 checksum
How to use checksums
a720c2618ca0c09800921dd0acaf2b57777f17eaf111e5aee01869fa0fa8fbf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.4.3 CPython/3.14.7 Darwin/25.6.0

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page