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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for slack_notifications_python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 570435245dc3a7c81665d0b20d49f3346780859860beccfcf0039275ba5863da
MD5 02ca97c39a75b61de5bd5474ec7c5f68
BLAKE2b-256 d60bfefc0a7307e70a3b311f8af0aac748c32a46b4166a3ffbb794a91abd0066

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for slack_notifications_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb9e57f1ecdce4b4334b33bd9564ca119bc01e998d50d14caaac8657bcf806e2
MD5 44fa114eeba8b7cb4f6cb1863b33bad1
BLAKE2b-256 8ac85b1c49ccdfe429ebb122ef08f3a76f6550ec1c88f617c44b926f5db03103

See more details on using hashes here.

Provenance

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