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.1.2.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.1.2-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for slack_notifications_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6381b7f3c0de8872c41425068f9ef6a5c58653dc0e167728b4afc2475741f54b
MD5 9151d84e26f842244a31803bdc02f99f
BLAKE2b-256 796451b098afa6147c2c5cb59c2a116bed36556c4dcdee97c675cb94f516a6c1

See more details on using hashes here.

Provenance

The following attestation bundles were made for slack_notifications_python-0.1.2.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.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for slack_notifications_python-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5ea306a1f48779b471b2ad48807f57e7502ae66f1636d5b9e8ced966d8343c2a
MD5 4775573e47c7115cc6a3308a356412b5
BLAKE2b-256 26150e537e83da5061c057c32be354eb5b7128f0a032347e4ca11a88858bc9b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for slack_notifications_python-0.1.2-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