Skip to main content

No project description provided

Project description

Slack Notifications Python

SlackNotifications is a lightweight, extensible Python library that simplifies sending rich notifications to Slack channels via incoming webhooks.

Installation

pip install slack-notifications-python

Quick Start

from typing import Dict, List

from traitlets import Any

from SlackNotifications.slack import (
    SlackChannelConfig,
    SlackNotificationService,
    SlackNotificationServiceConfig,
)


class ExtendedSlackNotificationService(SlackNotificationService):
    def __init__(self, config: SlackNotificationServiceConfig) -> None:
        super().__init__(config)

    def example_custom_method(
        self, channel_reference: str, title: str, line1: str, line2: str, line3: str
    ) -> None:
        blocks: List[Dict[str, Any]] = [
            self.divider_block(),
            self.section_block(self.bold_text(title)),
            self.section_block(self.italic_text(line1)),
            self.section_block(self.italic_text(line2)),
            self.section_block(self.italic_text(line3)),
            self.footer_block("Example Custom Message"),
        ]

        self.send_message(channel_reference, blocks)


# Example configuration for slack channels
channel_configs = [
    SlackChannelConfig(
        channel_reference="alerts",
        channel_webhook_url="https://hooks.slack.com/services/T00000000/B00000000/FAKEFAKEFAKEFAKEFAKEFAKE",
    ),
    SlackChannelConfig(
        channel_reference="notifications",
        channel_webhook_url="https://hooks.slack.com/services/T00000000/B00000000/FAKEFAKEFAKEFAKEFAKEFAKE",
    ),
]

# Initialize the Slack notification service
service_config = SlackNotificationServiceConfig(
    channels=channel_configs,
    send_to_slack=True,
    verbose=True,
)

# Initialise the extended service
slack_service = ExtendedSlackNotificationService(config=service_config)

# Example of sending a message
slack_service.example_custom_method(
    channel_reference="alerts",
    title="Alert Title",
    line1="This is the first line of the alert.",
    line2="This is the second line of the alert.",
    line3="This is the third line of the alert.",
)

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

slack_notifications_python-0.0.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

slack_notifications_python-0.0.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file slack_notifications_python-0.0.0.tar.gz.

File metadata

File hashes

Hashes for slack_notifications_python-0.0.0.tar.gz
Algorithm Hash digest
SHA256 36ab5072a1175e1a399747c75585f93b89d69d1ab2878657e0b917dac99a6299
MD5 1d2ea513482ccae3a14050b99a16e9d9
BLAKE2b-256 99f0b0eec28ed763b64443f38c6ae7a8ecaf8f4f4013ec8052003d7c9a03b833

See more details on using hashes here.

Provenance

The following attestation bundles were made for slack_notifications_python-0.0.0.tar.gz:

Publisher: publish.yml on M-JEFFRYES/slack-notifications-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 slack_notifications_python-0.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for slack_notifications_python-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78ec86c596a653ac3cd95960f1aa3bea3edf9002bd0f87150cf4016ddad27b79
MD5 7c87440430c2b92f310e53986f29d033
BLAKE2b-256 fa2d5b39e708686ad746a836ba1c0b62750bd32e8ff2b44c68ff42ba39924d3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for slack_notifications_python-0.0.0-py3-none-any.whl:

Publisher: publish.yml on M-JEFFRYES/slack-notifications-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